Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

setTimeout in React Native

$
0
0

I'm trying to load a splash screen for an iOS app built in React Native. I'm trying to accomplish this through class states and then a setTimeout function as follows:

class CowtanApp extends Component {  constructor(props){    super(props);    this.state = {      timePassed: false    };  }  render() {    setTimeout(function(){this.setState({timePassed: true})}, 1000);    if (!this.state.timePassed){      return <LoadingPage/>;    }else{      return (<NavigatorIOS          style = {styles.container}          initialRoute = {{            component: LoginPage,            title: 'Sign In',          }}/>      );    }  }}

The loading page works for a second, and then I guess when setTimeout tries to change the state to true, my program crashes: 'undefined is not an object (evaluating this.setState)'. I've been going at this for a couple of hours, any ideas on how to fix it?


Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>