reactjs - React native splash screen and navigate to different screen -


i beginner in using react native. want display splash screen apps (for 1 second) , navigate different screen. have followed , combined tutorial got error.

my code this:

class splashscreen extends react.component {     static navigationoptions = {header: null,}     constructor(props){         super(props);         this.state = {             timepassed: false         };     }      render() {         let = 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 error navigate new screen. can me? or there better solution? thank you.

try this

class splashscene extends component {   function timeout(ms) {     return new promise(resolve => settimeout(resolve, ms));   }    async function sleep(fn, ...args) {     await timeout(3000);     return fn(...args);   }    resetandnavigate() {     const resetaction = navigationactions.reset({       index: 0,       actions: [         navigationactions.navigate({ routename: 'login'})       ]     })     this.props.navigation.dispatch(resetaction)   }   componentdidmount() {     sleep.then(       this.resetandnavigate()     )   } } 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -