Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/slorber/react-native-storage-slot
- Owner: slorber
- License: mit
- Created: 2018-11-25T15:58:45.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T21:58:46.000Z (almost 2 years ago)
- Last Synced: 2024-10-04T16:59:17.421Z (about 1 month ago)
- Language: TypeScript
- Homepage: https://sebastienlorber.com
- Size: 1.56 MB
- Stars: 10
- Watchers: 4
- Forks: 2
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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).