Reputation: 721
How can run this function with delay for 5 second?
export default class Splash extends React.PureComponent {
constructor() {
super();
this._bootstrapAsync();
}
bootstrapAsync = async () => {
//await Task.Delay(5);
//await timeout(5000)
//await sleep(5000);
const userToken = await AsyncStorage.getItem('userToken');
this.props.navigation.navigate(userToken ? 'App' : 'Auth');
};
I tried these:
await Task.Delay(3);
And
await timeout(5000);
And
await sleep(2000);
Upvotes: 4
Views: 10537
Reputation: 18503
This promise resolves in ms
milliseconds:
const sleep = ms => new Promise(resolve => setTimeout(resolve, ms))
You use it like await sleep(5000)
instead of the code that didn't work for you.
Upvotes: 9