0.0.2 • Published 2 years ago
@drpiou/async-storage v0.0.2
@drpiou/async-storage
The @drpiou/async-storage
package wraps the @react-native-async-storage/async-storage
package.
- type AsyncStorage.
- written in TypeScript.
Compatibility
- React (17.0.2+)
- React Native (0.64.0+)
- Expo (43+)
Installation
yarn add @drpiou/async-storage
Peer Dependencies
React and React Native project:
yarn add @react-native-async-storage/async-storage@~1.17.3
Expo project:
expo install @react-native-async-storage/async-storage
Example
import { AsyncStorage } from '@drpiou/async-storage';
type StorageItemValueMap = {
lang_code: string;
theme: string;
};
const storage = new AsyncStorage<StorageItemValueMap>();
Documentation
class AsyncStorage<S extends Record<string, unknown>> {
getItem: <K extends keyof S, D extends S[K] | undefined>(
key: K,
defaultValue?: D,
autoSet?: boolean,
) => Promise<D extends undefined ? S[K] | undefined : S[K]>;
setItem: <K extends keyof S>(key: K, value: S[K]) => Promise<void>;
hasItem: (key: keyof S) => Promise<boolean>;
removeItem: (key: keyof S) => Promise<void>
}