繁体   English   中英

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

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

我正在使用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);
        }
      };

使用AsyncStorage而不是 KeyValueStorage 它与您使用的相同。

但是您不能在此传递整数类型值,您必须将它们转换为字符串。

这很简单。

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

其中userId是键, UserId是整数类型值,我们使用 '' 将内部值转换为字符串。

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

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM