首页 > 解决方案 > AsyncStorage 未定义检查

问题描述

如何确定 asyncstorage 是否在

错误拒绝

if (await AsyncStorage.getItem("id") == undefined){
    alert("yes");
}

标签: javascriptreact-nativeexpo

解决方案


实现这一点的更优雅的方法是:

const id = await AsyncStorage.getItem("id")   // Get the item reference of ID if exists

if (id) {
   // Do what you want if ID is actually there
} else {
   // Do what you want if ID is not there
}

推荐阅读