Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/slorber/react-native-storage-slot

A simple typed wrapper around AsyncStorage
https://github.com/slorber/react-native-storage-slot

Last synced: 21 days ago
JSON representation

A simple typed wrapper around AsyncStorage

Awesome Lists containing this project

README

        

# 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).

```tsx
interface FormState {
input: string
toggle: boolean
}

const FormStateStorage = createStorageSlot('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:

```tsx
export interface StorageSlot {
get: () => Promise;
set: (value: T) => Promise;
del: () => Promise;
}

export declare const createStorageSlot: (key: string) => StorageSlot;
```

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",`

# Hire a freelance expert

Looking for a React/ReactNative freelance expert with more than 5 years production experience?
Contact me from my [website](https://sebastienlorber.com/) or with [Twitter](https://twitter.com/sebastienlorber).