3

I'm using AsyncStorage from react-native to get and store data for my app. I successfully store data via AsyncStorage but when I try to getItem from AsyncStorage it

Promise {_40: 0, _65: 1, _55: "30", _72: null}

How to get "30" value? I tried .json and Promise.resolved to get the data, both not working.

react-native: "0.47.1"
android version: 6
1

3 Answers 3

4

if you want to get value from it you must do this :

you have 2 ways :

1.using async/await as code below :

async function(){
  var a = await someFunction(your_input);
  console.log(a)
}

2.using .then()

someFuntion(your_input).then((result)=>{
  console.log(result)
})
Sign up to request clarification or add additional context in comments.

Comments

2

this is solution:

    var data=''
    Promise.resolve(your_promise).then(value=>{
    console.log('value:',value)
    data=value;
    }) 

1 Comment

try to add more description of the solution.
1

You can use:

var myPromise = Promise.resolve({_40: 0, _65: 1, _55: "30", _72: null});
myPromise.then(
  value=>{
    console.log("get value._55",value._55);
  }
)

More on why promises are used and some info on how to use them can be found here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.