React Native error: Undefined is not a Function

Asked

Viewed 863 times

0

I’m having a bug in React

React Native error: Undefined is not a Function

import React, { Component } from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { connect } from 'react-redux';
import  checkLogin  from '../actions/AuthActions';


export class Preload extends Component {

    static navigationOptions = {
        title: '',
        header: null
    }

    constructor(props) {
        super(props);
        this.state = {};

        this.props.checkLogin();
    }



    render() {
        return (
            <View style={styles.container}>
                <Text>Carregando... {this.props.status}</Text>
            </View>
        );
    }

}

const styles = StyleSheet.create({
    container: {
        margin: 10
    }
});

const mapStateToProps = (state) => {
    return {
        status: state.auth.status
    };
};

const PreloadConnect = connect(mapStateToProps, { checkLogin })(Preload);
export default PreloadConnect;

1 answer

1


Your mapDispatchToProps it is wrong you have to do so, because the way Voce is doing it will not map the data in the React props :

const mapDispatchToProps = (dispatch) => ({
  checkLogin: () => dispatch(checkLogin())
})

export default connect(mapStateToProps, mapDispatchToProps)(Preload)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.