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 storing values other than strings而这个 https://facebook.github.io/react-native/docs/asyncstorage.html#setitem
谢谢。
关于react-native - 为什么 AsyncStorage getItem 返回 null?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48821354/