The official middleware persistor for nedux. Performant and flexible.
npm install nedux-persist --save
Name | Codesandbox |
---|---|
π Persisting Token | here |
// ES6
import { persistKeys } from 'nedux-persist';
// ES5
var persistKeys = require('nedux-persist').persistKeys;
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 |
argument | required | type | description |
---|---|---|---|
getItem |
β | (key: string) => string |
Get the value from Storage |
setItem |
β | (key: string, value: string) => void |
Set the value into Storage |
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}`) });
All Pull Requests, Issues and Discussions are welcomed !