javascript - AsyncStorage 未定义检查
问题描述
如何确定 asyncstorage 是否在
错误拒绝
if (await AsyncStorage.getItem("id") == undefined){
alert("yes");
}
解决方案
实现这一点的更优雅的方法是:
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
}
推荐阅读
- bash - 为什么我在发送标准输出后有一个空文件
- active-directory - 我们正在尝试使用 Azure AD SSO 使 Snowflake 工作 AD SSO 登录。Active Directory SSO 如何工作?
- apache-spark - spark order by 后跟 partition by
- bixby - 如何在缩略图上方插入布局宏
- javascript - 排序然后将数组中的每个项目相乘
- c# - 如何使用子元素触发父元素?
- python - 如何在不退出当前域的情况下重定向到外部链接?
- javascript - Chrome 中的 HighCharts 轴格式
- vuetify.js - 使用组合 api 和远程 api 进行 vuetify 自动完成?
- mysql - MySQL server has gone away 错误的罕见原因