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
Solution 1:
Try using clear() function which erases all AsyncStorage
for all clients, libraries, etc
Solution 2:
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>
Solution 3:
You can clear AsyncStorage easily without touching your source code. Using react native debugger; and in the devtools console type
$reactNative.AsyncStorage.clear();
or to call it in RN's normal debugger with clear()
you can put this in...
if (__DEV__) {
global.clear = () => {
AsyncStorage.clear().then(() => console.log('Cleared'))
}
}