首页 文章

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

提问于
浏览
1

正确的观点:

我正在使用Expo XDE with react-native来构建一个跨平台的移动应用程序 .

我想使用AsyncStorage(react-native中的“localstorage”替代)保存和检索几个变量 .

添加要存储和检索的代码片段后,

enter image description here

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

enter image description here

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

有任何想法吗?这只是与Expo XDE相关的问题吗?

谢谢!!

1 回答

  • 8

    包括 const username = await AsyncStorage.getItem(); 在内的函数需要异步 .

    你可以这样做:

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

相关问题