javascriptreact-nativesettimeoutreact-native-navigation

how to set timeout function in react native


I am new in React-Native. and I am trying to set image delay to load function in react native.

              <Image  style={{  width:250, height: 250 }}
                source={require('../images/cart.png')}
                onLoad={() => {
                   this.props.navigation.navigate('HomeScreen')
                }}
             />

I am trying this but it gets an error

                 onLoad={() => {
                   setTimeout(function(){
                      this.props.navigation.navigate('HomeScreen')
                  }, 3000);
                  }}

Solution

  • You might rewrite it using arrow function notation like this:

    setTimeout(() => {
    this.props.navigation.navigate('HomeScreen');
    }, 3000);