Search code examples
javascriptreact-nativeasyncstorage

Get Stored datas in react native


I am trying to recover my user password and id with an asynchronous function using the AsyncStorage API, only the present code does not execute ...

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}

Solution

  • Here is the solution: The AsyncStorage module work only without debug mode.