javascript - 在 componentWillReceiveProps 函数中调用 setTimeout 时无法解析模块计时器

标签 javascript react-native settimeout

在 componentWillReceiveProps 函数中调用 setTimeout 函数时出现 500 错误。

当我没有在 chrome 中调试时出现以下错误图像

enter image description here

我在 chrome 中调试时遇到以下错误

enter image description here

可以引用下面的代码

    componentWillReceiveProps(nextprops){
        this.setState({isLoading:true})

        var data =[];
        if(nextprops.tasks.length == 0){
          //this.setState({isLoading:false,isEmpty:true})
        }else{
          this.setState({ dataSource:ds.cloneWithRows(nextprops.tasks),isLoading: false, isError: false, isEmpty: false });
        }
        setTimeout(() => {
          if(nextprops.tasks.length == 0){
            this.setState({isLoading:false,isEmpty:true})
          }else{
            this.setState({ dataSource:ds.cloneWithRows(nextprops.tasks), isLoading: false, isError: false, isEmpty: false });
          }
        },5000);

      }

最佳答案

Visual Studio 自动添加

import {setTimeout} from "timers";

检查您的导入并将其删除。 setTimeout 函数不需要导入。

关于javascript - 在 componentWillReceiveProps 函数中调用 setTimeout 时无法解析模块计时器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49048427/

相关文章:

react-native - react 导航 state.params 不起作用

javascript - 如何为 React Native 生成​​文档?

angular - 如何获取在其外部 "SetTimeout"内部生成的值

javascript - 如何将选定价格和输入复选框价格Jquery结合起来?

javascript - Android 上的 React-native facebook 登录崩溃

javascript - Vue、Webpack、DC.js,最后是 Crossfilter

javascript - 运行 setTimeout 并更改时间值

javascript - 在不关闭的情况下在 setTimeout 中执行 jQuery 成员函数的方法?

javascript - 如何在 express js 中访问使用 app.set() 设置的变量

javascript - Ajax 调用给我一个未定义的 - 未定义的错误?