Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript TypeError:无法读取属性';设置';在React native中未定义的_Javascript_React Native_React Native Android - Fatal编程技术网

Javascript TypeError:无法读取属性';设置';在React native中未定义的

Javascript TypeError:无法读取属性';设置';在React native中未定义的,javascript,react-native,react-native-android,Javascript,React Native,React Native Android,我正在使用KeyValueStorage调用异步方法,我从“react native key-value-storage”导入了KeyValueStorage,但不知道出了什么问题 import KeyValueStorage from "react-native-key-value-storage" onsuccessLogin =async () => { try { await KeyValueStorage.set("userI

我正在使用KeyValueStorage调用异步方法,我从“react native key-value-storage”导入了KeyValueStorage,但不知道出了什么问题

   import KeyValueStorage from "react-native-key-value-storage"

    onsuccessLogin =async  () => {
        try {
          await KeyValueStorage.set("userId", data.userId);
          await KeyValueStorage.set("token", data.token);
          Actions.drawerMenu();
        } catch(error) {
            // Handle error
            console.log("Login-Error",error);
        }
      };
使用而不是KeyValueStorage它与您正在使用的相同

但不能在这种情况下传递整型值,必须将它们转换为字符串

这很简单

等待AsyncStorage.setItem('userId',''+userId+'')

其中,userId是键,userId是整型值,我们使用“”将内部值转换为字符串


希望它能帮助您并节省您的时间,因为我浪费了两天时间在AsyncStorage中传递整型值。

尝试
setItem
而不是
set
。当您在react native中有异步存储可用时,为什么要使用keyvalue storage!!!!setItem可用于AsyncStorage@DavidGildour!请使用由react本地社区自己开发的AsyncStorage。它的语法要简单得多。实际上,我刚刚在react native中导入了项目和新手。让我试试AsyncStorage谢谢大家@GauravRoy,abhikumar22