1.0.4 • Published 5 years ago

sync-redux-with-localstorage v1.0.4

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

This is middleware for sync redux store with localStorage

Every time when store change occurs, specified field automatically write to localStorage

Download

npm i sync-redux-with-localstorage -D

Example:

store

state.cats = [
   {
    name: 'Fat Cat',
    id: 1,
  },
 {
    name: 'Good Cat',
    id: 2,
  },
];

interface

const syncInterface = {
  cats: {
    id: true,
  },
}

usage

import syncReduxWithLocalstorage from 'sync-redux-with-localstorage';

export default createStore(
    rootReducer,
    composeWithDevTools(applyMiddleware(thunk, syncReduxWithLocalstorage(syncInterface))),
);

in localStorage will be saved:

  reduxLocalStorage: "{ "cats" : [{ "id": "1" }, { "id": "2" }]}"