I am beginner in using React Native. I want to display the splash screen for my apps (for 1 second) and the navigate to different screen. I have followed and combined some tutorial but I got an error.
My code is like this:
class SplashScreen extends React.Component {
static navigationOptions = {header: null,}
constructor(props){
super(props);
this.state = {
timePassed: false
};
}
render() {
let that = this;
setTimeout(function(){that.setState({timePassed: true})}, 1000);
const { navigate } = this.props.navigation;
if (!this.state.timePassed){
return (
<View style={styles.splashContainer}>
<Image source={require('./image/splash_screen.png')} style=
{styles.splash} />
</View>
);
}
else{
() => navigate('Login');
}
}
I got an error to navigate to new screen. Can anyone help me? or is there any better solution? Thank you.
Try this