Last active
February 23, 2018 09:21
-
-
Save phpsmarter/a32e0d0f8cfc6f7ea8a37bcd58062252 to your computer and use it in GitHub Desktop.
AsyncStorage async/await
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 { 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