@drpiou/async-storage
TypeScript icon, indicating that this package has built-in type declarations

0.0.2 • Public • Published

@drpiou/async-storage

GitHub GitHub package.json version Jest tests

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>
}

Readme

Keywords

none

Package Sidebar

Install

npm i @drpiou/async-storage

Weekly Downloads

1

Version

0.0.2

License

ISC

Unpacked Size

7.15 kB

Total Files

9

Last publish

Collaborators

  • dr.piou