加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

react-native – 为什么AsyncStorage getItem返回null?

发布时间:2020-12-15 16:20:06 所属栏目:百科 来源:网络整理
导读:export const USER_KEY = "isLoggedIn";export const phoneVerified = () = AsyncStorage.setItem(USER_KEY,1);export const userInfoVerified = () = AsyncStorage.setItem(USER_KEY,2); 我已经使用上面的函数来存储值,而使用下面的函数来获取值. export co
export const USER_KEY = "isLoggedIn";

export const phoneVerified = () => AsyncStorage.setItem(USER_KEY,1);
export const userInfoVerified = () => AsyncStorage.setItem(USER_KEY,2);

我已经使用上面的函数来存储值,而使用下面的函数来获取值.

export const isSignedIn = () => {
  return new Promise((resolve,reject) => {
    AsyncStorage.getItem(USER_KEY)
      .then(res => {
          console.log("from isSignedIn : "+res); //res is showing null.
        if (res !== null) {
          resolve(res);
        } else {
          resolve(0);
        }
      })
      .catch(err => reject(err));
  });
};

为什么这总是返回null?我正在尝试async / await但仍然是null.我想某种方式数据不存储.

解决方法

我担心你只能存储字符串.请参阅本 React Native AsyncStorage storing values other than strings和本 https://facebook.github.io/react-native/docs/asyncstorage.html#setitem

谢谢.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读