我的问题是setTimeout会运行‍about 5 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和我的设备的时间不匹配,我的电脑!

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

React-native相关问答推荐

没有给出相同价值观的时刻

如何在Recact Native中单击Back按钮后调用函数

原生react :顶部的滑块位置

有人可以帮我实现 Font.loadAsync

React Native Android:how to remove "overscroll effect" of ScrollView

No component found for view with name "ARTShape"

从 React-Native 应用程序中的另一个类访问静态变量?

'React native run android' 在模拟器中启动应用程序后立即停止

如何在 React Native 的无状态功能组件中扩展原生组件的 props TypeScript 接口?

try 添加包时出现错误duplicate entry:com/google/android/gms/internal/zzble.class

使用 React Native 打开 iOS iPad 模拟器

React-native Xcode 构建失败 -> 'RCTAssert.h file not found'

如何在 react-native 中从 AsyncStorage 中删除元素

如何使用 Expo 在真实的 iOS 设备上运行应用程序?

占位符文本在(多行)TextInput for Android(React Native)中的位置

如何在 React Native 中使用 Jest

react-native 元素/目录 struct 设置

动态改变 React Native Flat List 中的列数

是否可以将 Material UI 库与 React Native 一起使用?

如何在 react-native 中为带有图标的按钮建模