Created
April 30, 2017 10:56
-
-
Save arbaaz/f7330cc362af00b3080a3bd8957ca8e7 to your computer and use it in GitHub Desktop.
Storage middleware
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// utils/storage.js | |
export default function () { | |
return next => (reducer, initialState) => { | |
const store = next(reducer, initialState); | |
store.subscribe(() => { | |
const state = store.getState(); | |
saveState(state); | |
}); | |
return store; | |
}; | |
} | |
function saveState(state) { | |
localStorage.setItem('app', state); | |
} | |
// app.js | |
import storageMiddleware from 'utils/storage'; | |
const enhancer = compose( | |
applyMiddleware( | |
thunk, | |
), | |
storageMiddleware(), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@hardik