await 是 Expo XDE for React Native 中的保留字错误

await is a reserved word error in Expo XDE for React Native

说到点子上:

我正在使用 Expo XDE 和 react-native 来构建一个 cross-platform 移动应用程序。

我想使用 AsyncStorage 保存和检索几个变量("localstorage" react-native 中的替代方法)。

添加存储和检索代码后,

Expo XDE 在构建 JavaScript 包时显示以下错误:"await is a reserved word"

根据文档 (https://facebook.github.io/react-native/docs/asyncstorage.html),我必须在访问 AsyncStorage 时使用 "await"。

有什么想法吗?是否仅与 Expo XDE 相关的问题?

谢谢!!

要使用 await,您的函数 const username = await AsyncStorage.getItem(); 需要异步。

你可以这样做:

async myfunction() {
  ...
  const username = await AsyncStorage.getItem();
  ...
}