在本机反应中获取存储的数据

Get Stored datas in react native

我正在尝试使用 AsyncStorage API 的异步函数恢复我的用户密码和 ID,只有当前代码不执行 ...

async function getStoredDatas(){
    try{
       return {
           user: await AsyncStorage.getItem('@Store:user'),
           password: await AsyncStorage.getItem('@Store:password')
       };
    }
    catch(e){
       console.log("error:" + e); // never triggered
    }
}

let a = getStoredDatas().then( (datas) => {
    console.log("then: " + datas.user); // never triggered also
});

console.log(a); // Promise with this content: {_40: 0, _65: 0, _55: null, _72: null}

解决方法如下:AsyncStorage 模块只能在没有调试模式的情况下工作。