简体   繁体   English

类型错误:无法读取 React Native 中未定义的属性“set”

[英]TypeError: Cannot read property 'set' of undefined in React native

I am calling async method with KeyValueStorage , I imported KeyValueStorage from "react-native-key-value-storage" but don't know whats wrong.我正在使用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);
        }
      };

Use AsyncStorage instead of KeyValueStorage it is same as you are using .使用AsyncStorage而不是 KeyValueStorage 它与您使用的相同。

But you cannot pass integer type value in this you have to convert them into string.但是您不能在此传递整数类型值,您必须将它们转换为字符串。

and it is simple .这很简单。

await AsyncStorage.setItem('userId', '' + UserId + ''); await AsyncStorage.setItem('userId', '' + UserId + '');

where userId is the key and the UserId is the integer type value and we use '' to convert the inner value into the string.其中userId是键, UserId是整数类型值,我们使用 '' 将内部值转换为字符串。

Hope it will help you and save your time as i wasted two days in passing integer type value in AsyncStorage.希望它可以帮助您并节省您的时间,因为我浪费了两天在 AsyncStorage 中传递整数类型值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 "React-Native AsyncStorage:TypeError:无法读取未定义的属性“setItem”" - React-Native AsyncStorage: TypeError: Cannot read property 'setItem' of undefined React Native [TypeError:无法读取未定义的属性'startsWith']? - React Native [TypeError: Cannot read property 'startsWith' of undefined]? React Native TypeError:无法读取未定义的属性'projectName' - React Native TypeError: Cannot read property 'projectName' of undefined react-native - 类型错误:无法读取未定义的属性“修剪” - react-native - TypeError: Cannot read property 'trim' of undefined 类型错误:无法读取未定义的属性“导航”-反应本机 - TypeError: Cannot read property 'navigate' of undefined - React native 未捕获的类型错误:无法读取未定义的属性“映射”(REACT NATIVE - Javascript) - Uncaught TypeError: Cannot read property 'map' of undefined ( REACT NATIVE - Javascript ) React Native TypeError:无法读取undefined的属性'createClient' - React Native TypeError: Cannot read property 'createClient' of undefined React Native TypeError:无法读取未定义的属性“名称” - React Native TypeError: Cannot read property 'name' of undefined 反应本机导航错误-TypeError:无法读取未定义的属性'catch' - React native navigation error -TypeError: Cannot read property 'catch' of undefined TypeError:无法读取未定义的属性“s_path”(React Native) - TypeError: Cannot read property 's_path' of undefined (React Native)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM