Created
February 14, 2018 08:47
-
-
Save morishin/4d80fffc3ccf105f96f4162ea46b44fd 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'; | |
export default class GenericAsyncStorage { | |
static async getItem<T>(key: string, callback?: (error?: Error, result?: T) => void): Promise<T> { | |
const item = await AsyncStorage.getItem(key); | |
return JSON.parse(item); | |
} | |
static async setItem<T>( | |
key: string, | |
value: T, | |
callback?: (error?: Error) => void, | |
): Promise<void> { | |
await AsyncStorage.setItem(key, JSON.stringify(value)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment