Skip to content

Instantly share code, notes, and snippets.

@phpsmarter
Last active February 23, 2018 09:21
Show Gist options
  • Save phpsmarter/a32e0d0f8cfc6f7ea8a37bcd58062252 to your computer and use it in GitHub Desktop.
Save phpsmarter/a32e0d0f8cfc6f7ea8a37bcd58062252 to your computer and use it in GitHub Desktop.
AsyncStorage async/await
import { AsyncStorage } from 'react-native';
// retrieve
export const retrieve = async (key) => await AsyncStorage.getItem(key);
// store
export const store = async (key, value) => {
await AsyncStorage.setItem(key, value);
}
// store multiple keys
export const storeCredentials = async (token, permissions) => {
await AsyncStorage.multiSet([['token', token], ['permissions', JSON.stringify(permissions)]]);
};
// clear multiple keys
export const clearCredentials = async () => await AsyncStorage.multiRemove(['token', 'permissions']);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment