A value returned from a Promise is only accessible from within its .then()
callback. This means that res
is only available inside getTodos.then((res) => { ... })
.
storeData = async (value) => {
try {
const jsonValue = JSON.stringify(value);
await AsyncStorage.setItem("@Token", jsonValue);
} catch (e) {
// saving error
}
};
getData = () => {
const getTodos = AsyncStorage.getItem("@Token");
getTodos.then((res) => {
if (res !== null) {
return true;
} else {
return false;
}
});
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…