Skip to content

Instantly share code, notes, and snippets.

@david-bc
Last active April 25, 2018 20:31
Show Gist options
  • Save david-bc/45b3b3b770880218f6e2d860be9ac5e2 to your computer and use it in GitHub Desktop.
Save david-bc/45b3b3b770880218f6e2d860be9ac5e2 to your computer and use it in GitHub Desktop.
Redux LocalStorage Example
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