Created
February 1, 2018 03:14
-
-
Save kikoseijo/edc00af2dc7cf67b5d50802ba3bc292f to your computer and use it in GitHub Desktop.
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 get = async key => await AsyncStorage.getItem(key); | |
// store | |
export const set = async (key, value) => { | |
await AsyncStorage.setItem(key, value); | |
}; | |
export const setObj = async (key, value) => { | |
await AsyncStorage.setItem(key, JSON.stringify(value)); | |
}; | |
// store multiple keys | |
export const storeCredentials = async (token, permissions) => { | |
await AsyncStorage.multiSet([ | |
['token', token], | |
['permissions', JSON.stringify(permissions)] | |
]); | |
}; | |
// clear key | |
export const remove = async key => await AsyncStorage.removeItem(key); | |
// clear multiple keys | |
export const clearCredentials = async () => | |
await AsyncStorage.multiRemove(['token', 'permissions']); | |
export const printAllKeys = async () => { | |
await AsyncStorage.getAllKeys((err, keys) => { | |
AsyncStorage.multiGet(keys, (err, stores) => { | |
stores.map((result, i, store) => { | |
// get at each store's key/value so you can work with it | |
let key = store[i][0]; | |
let value = store[i][1]; | |
console.log('[key, value]', key, value); | |
}); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment