Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

vivcogit/redux-localstorage-saver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

23 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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());

About

Redux middleware for automatical save actions to localStorage.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published