2

I am trying to return the value from AsyncStorage without using the async function and await. When I use the below function, however, it returns undefined. Thank you in advance!

getAllFav(){
    var collect;
    const value = AsyncStorage.getAllKeys().then(
        (values) => {
            collect=values;
            return collect;
        }
    )
}
divibisan
  • 11,659
  • 11
  • 40
  • 58
Marcel
  • 33
  • 2
  • 7
  • 1
    Possible duplicate of [How do I return the response from an asynchronous call?](https://stackoverflow.com/questions/14220321/how-do-i-return-the-response-from-an-asynchronous-call) – T.J. Crowder Jun 14 '18 at 13:59
  • in the topic you mentioned is not explained how can i return the calue inside then. – Marcel Jun 14 '18 at 14:31
  • Right. Because the answers there quite clearly say you can't do that (so naturally they don't then say how to do the thing you can't do). They **do** tell you what to do instead, such as making `getAllFav` return a promise. You can't magically convert an asynchronous operation into a synchronous one. – T.J. Crowder Jun 14 '18 at 15:12

0 Answers0