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())}
/>
The code above was correct.👌
There was a problem, because I was in the debug mode
and my device's time don't matches that of my computer!
This happened to me and took an unfortunately long while to debug 😊
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.