1.1.0 • Published 4 years ago
nedux-persist v1.1.0
nedux-persist - persist your nedux store
The official middleware persistor for nedux. Performant and flexible.
📦 Installation
npm install nedux-persist --save
💻 Usage with examples
Name | Codesandbox | |
---|---|---|
🔒 Persisting Token | here | here |
📜 Documentation
Import
// ES6
import { persistKeys } from 'nedux-persist';
// ES5
var persistKeys = require('nedux-persist').persistKeys;
persistKeys(keys, [localStorage])
Create a middleware that may your keys
persisted.
argument | required | type | description |
---|---|---|---|
keys | ✅ | string[] | The keys that you want to persist |
localStorage | ❌ | Storage | The keys that you want to persist |
Storage
argument | required | type | description |
---|---|---|---|
getItem | ✅ | (key: string) => string | Get the value from Storage |
setItem | ✅ | (key: string, value: string) => void | Set the value into Storage |
🎛 Basic Usage
import { createStore } from 'nedux';
import { persistKeys } from 'nedux-persist';
type Store = {
token: string;
useless: number;
};
const store = createStore<Store>(
{ token: '', useless: 0 },
[persistKeys(['token'])],
);
store.subscribe('token', { next: token => console.log(`token: ${token}`) });
🙋🏼 Contributions
All Pull Requests, Issues and Discussions are welcomed !