Search code examples
react-nativeconsolelocal-storageasyncstorage

How to get data from Promise_ object?


I'm trying to get some data from a Promise_ object, in React Native app, in my AsyncStorage.

This is what I get in the console, in my Promise_ object :

Promise {_40: 0, _65: 0, _55: null, _72: null}
  _40: 0
  _55: {imageId: "1", imageName: "test.png"}
  _65: 1
  _72: null
__proto__: Object

So I don't know how to simply get the data in the _55 and show them in my code, I just want to take "1" and "test.png". And sorry for my bad english. Thanks !

CODE :

This is the code for the set : export const setBadgePicture = async (badgePictureId, badgePictureName) => await AsyncStorage.multiSet([['imageId', badgePictureId],['imageName', badgePictureName]])

and for the get : export const getBadgePicture = async () => { await AsyncStorage.multiGet(['imageId', 'imageName']).then((response) => { tableResponse = { 'imageId' : response[0][1], 'imageName' : response[1][1], } }) return tableResponse }


Solution

  • you can do this to wait until your AsyncStorage returns the item.

     AsyncStorage.getItem('YOUR_KEY').then((response)=>{
          const itemVal = response;
    })