Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wipe AsyncStorage in react native

I notice that I am wasting a certain amount of time debugging redux actions that I am persisting to AsyncStorage in react-native thanks to redux-persist. Sometimes I'd just like to wipe AsyncStorage to save some development time and try with fresh data.

EDIT: Best case the solution should work on simulators and real devices, iOS and Android. Maybe there are different work arounds for different platforms.

Thanks

like image 229
jsdario Avatar asked Sep 06 '16 09:09

jsdario


People also ask

How do I clear AsyncStorage data in React Native?

clear() ​ Erases all AsyncStorage for all clients, libraries, etc. You probably don't want to call this; use removeItem or multiRemove to clear only your app's keys.

How remove token AsyncStorage in React Native?

Just use AsyncStorage. removeItem('token'). It worked for me.

What is AsyncStorage in React Native?

AsyncStorage is a simple, asynchronous, unencrypted by default module that allows you to persist data offline in React Native apps. The persistence of data is done in a key-value storage system. There are numerous scenarios where this module can be beneficial.


2 Answers

Try using clear() function which erases all AsyncStorage for all clients, libraries, etc

like image 153
Tony Vincent Avatar answered Sep 25 '22 07:09

Tony Vincent


clearAsyncStorage = async() => {     AsyncStorage.clear(); } 

This function can be applied anywhere on the code base to clear AsyncStorage. For example, here is how it can be called on a <Button> component.

<Button onPress={this.clearAsyncStorage}>   <Text>Clear Async Storage</Text> </Button> 
like image 28
hzak Avatar answered Sep 24 '22 07:09

hzak