12345678910111213 |
- function localStoreReducer(reducer, localStorageKey) {
- function localStoredReducer(state, action) {
- if (state === undefined) {
- try {
- return JSON.parse(localStorage[localStorageKey]);
- } catch (e) { }
- }
- const newState = reducer(state, action);
- localStorage[localStorageKey] = JSON.stringify(newState);
- return newState;
- }
- return localStoredReducer;
- }
|