Javascript setTimeout立即在React Native中运行
我的问题是setTimeout运行<代码>大约5秒更早。 例如,当我将其设置为Javascript setTimeout立即在React Native中运行,javascript,react-native,settimeout,Javascript,React Native,Settimeout,我的问题是setTimeout运行大约5秒更早。 例如,当我将其设置为5秒时,它会立即运行,但当我使用15秒时,它会在大约10秒后运行 我甚至调查了这个问题,但我仍然无法解决这个问题 changeNotify() { let that = this; console.log("before"); setTimeout(function () { console.log("After"); that.setState({notifyModa
5秒
时,它会立即运行,但当我使用15秒
时,它会在大约10秒后运行
我甚至调查了这个问题,但我仍然无法解决这个问题
changeNotify() {
let that = this;
console.log("before");
setTimeout(function () {
console.log("After");
that.setState({notifyModal: false})
}, 5000);
}
在渲染中
<Button
title='change'
onPress={() => this.setState({notifyModal: true},()=>this.changeNotify())}
/>
this.setState({notifyModal:true},()=>this.changeNotify())}
/>
上面的代码是正确的。如果这解决了问题,请选择它作为所选答案。是的,即使你自己解决了。我可以在两天后确认我的答案。这条定律被认为是错误的,我无法想象这个解决方案能完美地工作,