【发布时间】:2018-08-14 16:04:45
【问题描述】:
我尝试使用 Asyncstorage 从数据库中获取数据,如下所示。
async () => {
var x;
await AsyncStorage.getItem('DB', (err, result) => {
x = result; // I'm getting the data here
});
return JSON.parse(x);// this statement gets executed before I get values from result to x
},
我的问题如下 1)代码应该放在哪里(在componentDidMount或构造函数中) 2)我应该如何将值放入 this.state.dataList
由于在 .then of promise 返回另一个 promise 我无法在 this.state.dataList 中获取值
【问题讨论】:
标签: android ios reactjs react-native asyncstorage