react-native-storage-slot
A tiny typed wrapper around ReactNative AsyncStorage, perfect for TS
Last updated a year ago by slorber .
MIT · Original npm · Tarball · package.json
$ cnpm install react-native-storage-slot 
SYNC missed versions from official npm registry.

react-native-storage-slot

A tiny wrapper around AsyncStorage, particularly suited for typed interactions with AsyncStorage.

This is mostly useful to have a typed object store (shipping with TypeScrip defs) but can also be useful with JS (except).

interface FormState {
  input: string
  toggle: boolean
}

const FormStateStorage = createStorageSlot<FormState>('form') 

const test = async () => {

  // Store some data
  await FormStateStorage.set({input: "", toggle: true})

  // Read some data
  const formState = await FormStateStorage.get()!
  
  // Clear stored data
  await FormStateStorage.del();
  
}

API:

export interface StorageSlot<T> {
    get: () => Promise<T | undefined>;
    set: (value: T) => Promise<void>;
    del: () => Promise<void>;
}

export declare const createStorageSlot: <T extends {}>(key: string) => StorageSlot<T>;

The value you store should be serializable with JSON.parse / JSON.stringify.

DEV

To run example app in Expo, replace in package.json: "main": "node_modules/expo/AppEntry.js",`

Current Tags

  • 1.0.5                                ...           latest (a year ago)

5 Versions

  • 1.0.5                                ...           a year ago
  • 1.0.3                                ...           a year ago
  • 1.0.2                                ...           a year ago
  • 1.0.1                                ...           a year ago
  • 1.0.0                                ...           a year ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (16)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |