簡體   English   中英

Javascript setTimeout 立即在 React Native 中運行

[英]Javascript setTimeout Immediately runs in React Native

我的問題是setTimeout的運行about 5 seconds更早。 例如,當我將其設置為5 seconds ,它會立即運行,但是當我設置為15 seconds ,它會在大約10 seconds后運行。

我什至調查了這個問題: 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 mode ,我的設備時間與我的電腦時間不匹配!

這發生在我身上,不幸的是花了很長時間來調試😊

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM