Skip to content

Instantly share code, notes, and snippets.

@LucasFsc
Created June 22, 2020 15:43
Show Gist options
  • Save LucasFsc/d4ad0facec8af12c31fecd3ca74d30f6 to your computer and use it in GitHub Desktop.
Save LucasFsc/d4ad0facec8af12c31fecd3ca74d30f6 to your computer and use it in GitHub Desktop.
A simple function for RN to help with AsyncStorage
import AsyncStorage from '@react-native-community/async-storage'
export default key => ({
set: payload => AsyncStorage.setItem(key, JSON.stringify(payload)),
get: async () => {
const _ = AsyncStorage.getItem(key)
return _ ? JSON.parse(_) : null
},
remove: () => AsyncStorage.removeItem(key)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment