Created
May 21, 2018 11:59
-
-
Save JonatanSalas/5d97ed7c453dc19aabef5904046bef7f to your computer and use it in GitHub Desktop.
Revisions
-
Jonatan E. Salas created this gist
May 21, 2018 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,35 @@ import { AsyncStorage } from 'react-native'; class Storage { static async setItem(key, value, cb) { try { await AsyncStorage.setItem(`${key}`, JSON.strigify(value), cb); return true; } catch (err) { return false; } } static async getItem(key, cb) { try { const value = await AsyncStorage.getItem(`${key}`, cb); if (!value) { return false; } return JSON.parse(value); } catch (err) { return false; } } } // Usage await Storage.setItem(1, { 1: "hello world" }); const value = await Storage.getItem(1); //{ 1: "hello world" } console.info(value);