0

In order to set value in AsyncStorage we use

await AsyncStorage.setItem();

but what is the difference if I use

AsyncStorage.setItem() ; //Not used await.

I've tried it and value will get set to AsyncStorage.

Is it guarantee that value will get set without await all the time ?

I know using await will wait till the promise get resolved from the setItem().

At the asyncStorage documentation also they have used await, If it works without await then why to use the await all the time.

Kailash
  • 777
  • 4
  • 19
  • 1
    https://stackoverflow.com/questions/54586703/react-native-asyncstorage-using-await-and-async looks a valid explaination https://stackoverflow.com/questions/37120305/waiting-for-asyncstorage-getitem similar to your question – Shashank Malviya Oct 04 '22 at 04:18
  • Thanks @ShashankMalviya I've gone through it, but "Is it guarantee that value will get set without `await` all the time ?" - this query is still not answered actually. – Kailash Oct 04 '22 at 04:24
  • 1
    The value will set but if you want to wait for your next line of code to use the updated value, You should use async await promises. Thats the only point in making it as promise, So that It ensures that your ```local storage set & get ``` has been executed successfully. – Shashank Malviya Oct 04 '22 at 04:28

0 Answers0