admin管理员组文章数量:1289868
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);
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);
Share
Improve this question
edited Mar 26, 2019 at 0:32
Areza
asked Mar 26, 2019 at 0:28
ArezaAreza
7212 gold badges15 silver badges30 bronze badges
3
-
1
setTimeout
? . – zerkms Commented Mar 26, 2019 at 0:30 - May be it's wrong. I googled it. – Areza Commented Mar 26, 2019 at 0:32
-
You put inside the function
setTimeout(function() { // run here the user token }, 5000);
. SobootstrapAsync = async () => { // setTimeout }
– ABC Commented Mar 26, 2019 at 0:34
1 Answer
Reset to default 9This 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.
本文标签: javascripthow can I run async await with delay in reactnative componentStack Overflow
版权声明:本文标题:javascript - how can I run async await with delay in react-native component? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741408295a2377079.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论