npm

redux-localstorage-saver

1.0.2 • Public • Published

redux-localstorage-saver

David npm

Redux middleware for automatical save actions to localStorage with restore by action

Install

npm install redux-localstorage-saver

Usage

Init store:

import { createStore, applyMiddleware } from 'redux';
import localStorageMiddleware from 'redux-localstorage-saver';
 
import rootReducer from './reducer';
 
const SAVED_ACTIONS = ['FIRST_ACTION2SAVE', 'SECOND_ACTION2SAVE'];
 
const store = createStore(rootReducer, 
    applyMiddleware(localStorageMiddleware(SAVED_ACTIONS))
);

Or you can use extended config:

const config = {
  items: <array of saved actions>,
  serialize: <serialize function>,
  deserialize: <deserialize function>,
  prefix: <prefix for saved items names>
};
 
const store = createStore(rootReducer, 
    applyMiddleware(localStorageMiddleware(config))

Restore state

For restore state you need dispatch plain function "restore":

import { restore } from 'redux-localstorage-saver';
 
store.dispatch(restore());

Package Sidebar

Install

npm i redux-localstorage-saver

Weekly Downloads

1

Version

1.0.2

License

MIT

Unpacked Size

7.21 kB

Total Files

5

Last publish

Collaborators

  • vivcogit