Javascript setTimeout Immediately runs in React Na

2019-06-17 18:10发布

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())}
/>

1条回答
闹够了就滚
2楼-- · 2019-06-17 19:05

The code above was correct.

查看更多
登录 后发表回答