Skip to content

Latest commit

 

History

History
70 lines (47 loc) · 2.65 KB

README.md

File metadata and controls

70 lines (47 loc) · 2.65 KB

nedux-persist - persist your nedux store

typescript version size

The official middleware persistor for nedux. Performant and flexible.

📦 Installation

npm install nedux-persist --save

💻 Usage with examples

Name Codesandbox
🔒 Persisting Token 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 !