Skip to content

Instantly share code, notes, and snippets.

@morishin
Created February 14, 2018 08:47
Show Gist options
  • Save morishin/4d80fffc3ccf105f96f4162ea46b44fd to your computer and use it in GitHub Desktop.
Save morishin/4d80fffc3ccf105f96f4162ea46b44fd to your computer and use it in GitHub Desktop.
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