0

How to mananged many id after i'm choosing diferrent id using asyncstorage ?

my problem is im currently using setitem to set my id and get that id in whole part of my apps but , i wanted to set and get diferrent id too , and remove that old id , any suggestion doing the best way to do that , thank you 😁😁

1 Answer 1

1

You can set different items with different keys.

AsyncStorage.setItem('id','1234');
AsyncStorage.setItem('id2','3334');

If you want to use just one key:

AsyncStorage.removeItem('id');

You can remove an item just like that.

Sign up to request clarification or add additional context in comments.

6 Comments

i really understand to use this but, how i can set , get ,and remove in the same time without having problems with race condition cause i'm passing my props into setitem , and i wanted to remove old id and get my new id
So, I can understand you want to use one key. When you use setItem('id',123), id will be 123. After that if you use it again with different value like setItem('id',321), old value(123) will be deleted and id will be the new value(321).
currently i also trying using codition but seems my condition not doing well and i'm using lifecycle too , like componenetdidmount and componentwillmout
This is asyncstorage, so it's working async. You have to wait for result for use in condition. await AsyncStorage.getItem(...) will work.
i 'm also using await too to get there but it doesnt work my id still undefined
|

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.