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

标签 react-native asyncstorage

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 但仍然为空。我认为不知何故数据没有存储。

最佳答案

关于react-native - 为什么 AsyncStorage getItem 返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48821354/

相关文章:

javascript - react native : Import modules outside of project directory

reactjs - React Native ListView 性能太慢?

session - 异步存储 : React Native

javascript - AsyncStorage.getItem() 返回一个值和一个 promise

javascript - 使用项目组中的 React Native State 管理选定的项目样式

reactjs - 如何使用 Redux Provider 包装导航堆栈(createSwitchNavigator)?

reactjs - AsyncStorage 不存储数据,随后不检索数据

react-native - redux 坚持/getStoredState : Error restoring data for key: xxxxx

javascript - AsyncStorage 返回意外错误

firebase - 如何将 firebase TestLab 与 React Native 结合使用