首页 > 解决方案 > 启动反应本机应用程序时出现异常

问题描述

我无法找到我做错的地方

当我运行 Metro bundler 时会发生这种情况

BUNDLE  [android, dev] ./index.js ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ 100.0% (1491/1491), done.

 LOG  Running "Trepr" with {"rootTag":1}
 WARN  Possible Unhandled Promise Rejection (id: 0):
TypeError: Cannot read property 'length' of undefined
TypeError: Cannot read property 'length' of undefined
    at render (http://10.0.3.2:8081/index.bundle?platform=android&dev=true&minify=false:183726:35)
    at finishClassComponent (http://10.0.3.2:8081/index.bundle?platform=android&dev=true&minify=false:17810:43)

标签: react-native

解决方案


您可以尝试获取数组legnth的属性。null所以你需要这样编码..

array !== null && array !== undefined && array.length

推荐阅读