Javascript setTimeout立即在React Native中运行

Mah*_*our 7 javascript settimeout react-native

我的问题是setTimeout运行吗?about 5 seconds较早。例如,当我将其设置为时5 seconds,它将立即运行,但是当我在上时15 seconds,它将在10 seconds以后运行。

我什至调查了这个问题:React Native中的setTimeout,但是我仍然无法解决问题

changeNotify() {
    let that = this;
    console.log("before");
    setTimeout(function () {
        console.log("After");
        that.setState({notifyModal: false})
    }, 5000);
}
Run Code Online (Sandbox Code Playgroud)

并在渲染

<Button
   title='change'
   onPress={() => this.setState({notifyModal: true},()=>this.changeNotify())}
/>
Run Code Online (Sandbox Code Playgroud)

Mah*_*our 14

上面的代码是正确的。

有一个问题,因为我在debug mode和我的设备使用的时间与我的计算机不匹配!

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