[英]Javascript setTimeout Immediately runs in React Native
My problem is that setTimeout runs about 5 seconds
earlier.我的问题是setTimeout的运行about 5 seconds
更早。 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.例如,当我将其设置为5 seconds
,它会立即运行,但是当我设置为15 seconds
,它会在大约10 seconds
后运行。
I even surveyed this question: setTimeout in React Native , but I still could not solve the problem我什至调查了这个问题: setTimeout in React Native ,但我仍然无法解决问题
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!有问题,因为我处于debug mode
,我的设备时间与我的电脑时间不匹配!
This happened to me and took an unfortunately long while to debug 😊这发生在我身上,不幸的是花了很长时间来调试😊
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.