# react-native-storage-slot

> A tiny typed wrapper around ReactNative AsyncStorage, perfect for TS

Latest version **2.0.0** (published 2020-07-01) · 0 weekly downloads

## Install

```sh
npm install react-native-storage-slot
pnpm add react-native-storage-slot
yarn add react-native-storage-slot
bun add react-native-storage-slot
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2020-07-01 |
| First published | 2018-11-26 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | slorber, xcarpentier |
| Keywords | react, react-native, storage |

## Links

- npm: https://www.npmjs.com/package/react-native-storage-slot
- npm.io page: https://npm.io/package/react-native-storage-slot

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2020-07-01
- 1.0.5 — 2018-11-26
- 1.0.3 — 2018-11-26
- 1.0.2 — 2018-11-26
- 1.0.1 — 2018-11-26
- 1.0.0 — 2018-11-26

## 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<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:

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

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

---
_Source: https://npm.io/package/react-native-storage-slot · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
