I'm working with react native and right now I getting the following error when I tried to mount my loading component.
TypeError: undefined is not an object (evaluating 'this.props.navigation.navigate')
Here is my code
import React from 'react';
import SplashScreen from 'react-native-splash-screen';
import Loading from '../../components/loading/Loading';
import { connect } from 'react-redux';
class LoadingContainer extends React.Component {
componentDidMount() {
setTimeout(() => {
SplashScreen.hide();
}, 300);
let initRoute;
if (this.props.auth.user) {
initRoute = 'App';
} else {
initRoute = 'Login';
}
this.props.navigation.navigate(initRoute);
}
render() {
return <Loading navigation={this.props.navigation} />;
}
}
const mapStateToProps = state => ({
auth: state.auth,
});
export default connect(mapStateToProps, null)(LoadingContainer);
Is the first time I getting this error while using react-navigation, I'm using the version 2.11.2 of react navigation
import React from 'react'; import { createSwitchNavigator } from 'react-navigation'; import App from './AppNavigator'; import LoadingContainer from '../containers/LoadingContainer/LoadingContainer'; import Login from '../containers/LoginContainer/Login'; export default createSwitchNavigator( { Loading: () => <LoadingContainer />, Login: () => <Login />, }, { initialRouteName: 'Loading', }, );- Gabriel Gonzalez