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
}))
)
));
相关文章