Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- TypeError: undefined is not a function (evaluating 'dispatch((0, _LoginActions.loginAction)(inputFormProp))')
- import React, { Component } from 'react';
- import { Text, View, TextInput, ActivityIndicator, TouchableHighlight } from 'react-native';
- import { getLogger, issueToText } from '../core/utils';
- import styles from '../core/styles';
- import { Card, Button, FormLabel, FormInput } from "react-native-elements";
- import { connect } from 'react-redux'
- import {loginAction} from '../actions/LoginActions'
- export class LoginComponent extends Component {
- constructor(props) {
- super(props);
- this.login = this.login.bind(this)
- }
- render() {
- const { error, isLoading, username, password } = this.props;
- const inputFormProp = {
- username: '',
- password: ''
- };
- return (
- <View style={{ paddingVertical: 20 }}>
- <Card>
- <FormLabel>Email</FormLabel>
- <FormInput value={username} onChangeText={(text) => inputFormProp.username = text} />
- <FormLabel>Password</FormLabel>
- <FormInput value={password} onChangeText={(text) => inputFormProp.password = text} />
- <Button
- buttonStyle={{ marginTop: 20 }}
- backgroundColor="#03A9F4"
- title="SIGN IN"
- onPress={this.login(inputFormProp)}
- />
- </Card>
- <ActivityIndicator animating={this.props.isLoading} style={styles.activityIndicator} size="large" />
- </View>
- );
- }
- login(inputFormProp) {
- const { store } = this.props.screenProps.store;
- const { dispatch } = this.props
- dispatch(loginAction(inputFormProp))
- .then(() => {
- if (this.props.error === null && this.props.isLoading === false) {
- if (store.getState().auth.token) {
- this.props.navigation.navigate('ProductList', { token: store.getState().auth.token });
- }
- }
- })
- .catch(error => {
- });
- }
- }
- function mapStateToProps(state) {
- const { error, isLoading } = state.auth
- return {
- error,
- isLoading,
- }
- }
- export default connect(mapStateToProps)(LoginComponent)
- const initialState = {
- auth: { isLoading: false, error: null },
- };
- const rootReducer = combineReducers({ product: productReducer, auth: authReducer
- });
- const store = createStore(rootReducer, initialState, applyMiddleware(thunk,
- createLogger()));
- export const MyNavigator = StackNavigator({
- Login: { screen: LoginComponent },
- ProductList: { screen: ProductList },
- });
- export default class App extends Component {
- render() {
- return (
- <MyNavigator screenProps={{ store: { store } }} />
- );
- }
- };
Add Comment
Please, Sign In to add comment