当前位置 : 主页 > 网页制作 > React >

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

来源:互联网 收集:自由互联 发布时间:2021-06-15
export const USER_KEY = "isLoggedIn";export const phoneVerified = () = AsyncStorage.setItem(USER_KEY, 1);export const userInfoVerified = () = AsyncStorage.setItem(USER_KEY, 2); 我已经使用上面的函数来存储值,而使用下面的函数
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

谢谢.

网友评论