Promise allSettled 不是函数 [英] Promise allSettled is not a function

查看:90
本文介绍了Promise allSettled 不是函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划在我的 React Native - Expo 项目中将一些 Promise.all 更新为 Promise.allSettled,但该功能不存在.我检查了所有版本,一切都合适,但我仍然无法使用该功能.

I planned updating some Promise.all to Promise.allSettled in my React Native - Expo Project but the function does not Exist. i checked all Versions and everything fits but i still cant use the function.

节点-v:14.15.4

node -v: 14.15.4

expo SDK -v 版本:^40.0.1

expo SDK -v version: ^40.0.1

expo 在其 SDK 版本中使用 react native -v 0.63.这应该不是问题.这是错误信息:

expo uses react native -v 0.63 in their SDK version. This should not be the problem. This is the error message:

Promise.allSettled 不是函数

Promise.allSettled is not a function

有人知道这个问题的解决方案吗?感谢您的帮助!

Does anybody knows a solution to this? Thank you for your help!

推荐答案

对于遇到此问题的任何人,显然这已在 v64 中修复:

For anyone coming across this issue, apparently this was fixed in v64:

https://github.com/facebook/react-native/issues/30236#issuecomment-939286987

对于旧版本,您可以使用简单的 polyfill:

For older versions, you can use a simple polyfill:

Promise.allSettled = Promise.allSettled || ((promises) => Promise.all(
    promises.map(p => p
        .then(value => ({
            status: "fulfilled",
            value
        }))
        .catch(reason => ({
            status: "rejected",
            reason
        }))
    )
));

这篇关于Promise allSettled 不是函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆