A. *_*san 5 react-native asyncstorage
export const USER_KEY = "isLoggedIn";
export const phoneVerified = () => AsyncStorage.setItem(USER_KEY, 1);
export const userInfoVerified = () => AsyncStorage.setItem(USER_KEY, 2);
Run Code Online (Sandbox Code Playgroud)
我使用了上面的函数来存储值和下面的函数来获取值。
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));
});
};
Run Code Online (Sandbox Code Playgroud)
为什么这总是返回null?我正在尝试 async/await 但仍然为空。我认为不知何故数据没有存储。
| 归档时间: |
|
| 查看次数: |
9353 次 |
| 最近记录: |