AsyncStorage 未解析或拒绝 [英] AsyncStorage not resolving or rejecting

查看:61
本文介绍了AsyncStorage 未解析或拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从异步存储中获取项目.

I'm trying to get an item from async storage.

componentDidMount() {
    console.log('componentDidMount')
    AsyncStorage.getItem(STORAGE_KEY)
      .then(storage => console.log('then', storage))
      .catch(err => console.log('catch', err))
}

也尝试这种方式:

componentDidMount() {
    console.log('componentDidMount')
    AsyncStorage.getItem(STORAGE_KEY, (err, data) => {
      console.log('data', data);
      console.log('err', err)
    });
 }

但无论我怎么做,调试器都只输出 componentDidMount 日志,而我根本没有得到结果.

But no matter how I do it, the debugger is outputting only the componentDidMount log and I'm not getting results at all.

知道这里出了什么问题吗?

Any idea what's wrong here?

我正在通过博览会运行应用

I'm running the app through expo

推荐答案

expo 出现问题.重新启动博览会后,我最初发布的代码完全相同.

There was a problem with expo. After restarting expo completely the same code I originally posted worked fine.

这篇关于AsyncStorage 未解析或拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆