Last active
July 3, 2021 19:35
-
-
Save rickyalmeidadev/badcf5f82bef31634e87af69eea4a99c to your computer and use it in GitHub Desktop.
Adds a menu item to clear AsyncStorage in DevSettings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { DevSettings, Platform, ToastAndroid } from 'react-native' | |
import AsyncStorage from '@react-native-async-storage/async-storage' | |
import Snackbar from 'react-native-snackbar' | |
DevSettings.addMenuItem('Clear AsyncStorage', async () => { | |
const keys = await AsyncStorage.getAllKeys() | |
await AsyncStorage.multiRemove(keys.filter(key => !key.includes('@REACTOTRON'))) | |
const message = 'AsyncStorage has been cleared' | |
if (Platform.OS === 'android') { | |
ToastAndroid.show(message, ToastAndroid.SHORT) | |
} else { | |
Snackbar.show({ text: message, duration: Snackbar.LENGTH_LONG }) | |
} | |
}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yarn add @react-native-async-storage/async-storage react-native-snackbar |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment