Skip to content

Instantly share code, notes, and snippets.

@davidgilbertson
Last active June 18, 2016 07:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidgilbertson/5330d167fa73c5580d64c4c1c0585086 to your computer and use it in GitHub Desktop.
Save davidgilbertson/5330d167fa73c5580d64c4c1c0585086 to your computer and use it in GitHub Desktop.
import {createStore} from 'redux';
import reducers from './reducers';
const localState = JSON.parse(localStorage.getItem('malla-store'));
const store = createStore(reducers, localState);
// Let's write the store to local storage every time it changes
let timer;
store.subscribe(() => {
clearTimeout(timer);
timer = setTimeout(() => {
localStorage.setItem('malla-store', JSON.stringify(store.getState()));
}, 500);
});
export default store;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment