最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Javascript setTimeout Immediately runs in React Native - Stack Overflow

programmeradmin3浏览0评论

My problem is that setTimeout runs ‍about 5 seconds earlier. For example, when I set it to 5 seconds, it runs immediately, but when I am on the 15 seconds, it will run for about 10 seconds later.

I even surveyed this question: setTimeout in React Native, but I still could not solve the problem

changeNotify() {
    let that = this;
    console.log("before");
    setTimeout(function () {
        console.log("After");
        that.setState({notifyModal: false})
    }, 5000);
}

And in render

<Button
   title='change'
   onPress={() => this.setState({notifyModal: true},()=>this.changeNotify())}
/>

My problem is that setTimeout runs ‍about 5 seconds earlier. For example, when I set it to 5 seconds, it runs immediately, but when I am on the 15 seconds, it will run for about 10 seconds later.

I even surveyed this question: setTimeout in React Native, but I still could not solve the problem

changeNotify() {
    let that = this;
    console.log("before");
    setTimeout(function () {
        console.log("After");
        that.setState({notifyModal: false})
    }, 5000);
}

And in render

<Button
   title='change'
   onPress={() => this.setState({notifyModal: true},()=>this.changeNotify())}
/>
Share Improve this question asked Jul 3, 2018 at 22:01 Mahdi BashirpourMahdi Bashirpour 18.8k16 gold badges129 silver badges151 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 31

The code above was correct.

发布评论

评论列表(0)

  1. 暂无评论