Skip to content

lucasmrdt/nedux-persist

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

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 !