android - React Native:调用 JSTimers.CallTimers 时出错
问题描述
我正在尝试在 Android(一加 6t)上运行我的应用程序。这在调用 firebase 之前运行良好,但是一旦我将该行添加onSend={Fire.shared.send}
到 Chat.js,应用程序就会崩溃。日志只显示未捕获的错误:调用 JSTimers.CallTimers 时出错。在其他任何地方都没有看到这个错误。有谁知道是什么问题?
解决方案
如果在将 JS 对象发送到本机端时省略了 await 调用,则可能会出现此错误,因此传递的是 promise 而不是结果。
我正在使用包装 setTimeout 的典型异步睡眠模式,因此这也可能是此错误呈现方式的一个因素,我不完全确定。
这是未经测试的,但这样的事情应该重现它:
// some async func
const asyncGetResult = async () => {
await sleep(17);
// etc.
return Promise.resolve(result);
};
// this should cause the error:
MyNativeComponent.nativeMethod({
result: asyncFunc() // <- missing 'await'
});
// this should not cause the error:
MyNativeComponent.nativeMethod({
result: await asyncFunc()
});
如果您不知道自己在寻找什么,这可能很难追踪。我采用了消除过程,逐个文件还原更改,直到找到有问题的行。希望这可以节省一些时间。
推荐阅读
- html - 溢出`scroll`剪辑flex内容
- conda - Windows Powershell 中的 CondaHTTPError
- python - Searching for an dictionary value inside a list
- r - 根据另一个数据框替换 R 中数据框中的字符值
- flutter - firebase_messaging 回调在前台时不会触发。iOS 应用 Flutter
- java - 使用 groovy 脚本将 XML 中的值替换为 ParseText
- python - 深度 Q 学习:关于反向传播的问题
- javascript - 通过 setState 在反应中清空对象的所有值的更好方法
- regex - 2个日期之间的匹配数
- django - 有没有办法“锁定”页面以防其他用户正在编辑 - DJANGO