Last active
April 25, 2018 20:31
-
-
Save david-bc/45b3b3b770880218f6e2d860be9ac5e2 to your computer and use it in GitHub Desktop.
Redux LocalStorage Example
This file contains 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
import {compose, createStore} from 'redux' | |
import rootReducer from './reducers' | |
// v v v v v +1 line v v v v v v | |
// npm install --save redux-localstorage | |
import persistState from 'redux-localstorage' | |
// ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ | |
const persistedSlices = ['auth', 'constants', 'myStuff'] | |
const enhancer = compose( | |
/* [other middlewares] */, | |
// v v v v v +1 line v v v v v v | |
persistState(persistedSclices), | |
// ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ | |
) | |
const initalState = {} | |
const store = createStore(rootReducer, initialState, enhancer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment