代码之家  ›  专栏  ›  技术社区  ›  Mahdi Bashirpour

javascript settimeout立即在react native中运行

  •  7
  • Mahdi Bashirpour  · 技术社区  · 6 年前

    我的问题是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())}
    />
    
    1 回复  |  直到 6 年前
        1
  •  14
  •   Mahdi Bashirpour    5 年前

    上面的代码是正确的。

    有个问题是因为我在 debug mode 我的设备的时间和我的电脑的时间不匹配!

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