gpt4 book ai didi

Javascript setTimeout 立即在 React Native 中运行

转载 作者:数据小太阳 更新时间:2023-10-29 04:31:43 26 4
gpt4 key购买 nike

我的问题是 setTimeout 提前了 ‍大约 5 秒 运行。例如,当我设置为5秒时,它会立即运行,但是当我设置在15秒时,它会运行大约10秒 稍后。

我什至调查了这个问题:setTimeout in React Native , 但还是没能解决问题

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

最佳答案

上面的代码是正确的。👌

有一个问题,因为我处于 Debug模式,我的设备时间与我的电脑时间不匹配!

这件事发生在我身上,不幸的是花了很长时间来调试😊

关于Javascript setTimeout 立即在 React Native 中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51163349/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com