Skip to content

Instantly share code, notes, and snippets.

@yildiz
Forked from rohozhnikoff/storage.js
Created March 4, 2018 12:34
Show Gist options
  • Save yildiz/5a3cac7f88df6f338cdec4cc35fcf091 to your computer and use it in GitHub Desktop.
Save yildiz/5a3cac7f88df6f338cdec4cc35fcf091 to your computer and use it in GitHub Desktop.
[react-native] wrapped AsyncStorage with JSON support
import { AsyncStorage } from 'react-native';
const JSONAsyncStorage = Object.assign({}, AsyncStorage, {
getItem() {
return AsyncStorage.getItem.apply(null, arguments).then((res) => JSON.parse(res));
},
setItem(key, value) {
return AsyncStorage.setItem(key, JSON.stringify(value))
}
});
export default JSONAsyncStorage;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment