Created
February 26, 2018 10:25
-
-
Save thedevdavid/c119cbe06520364257ee36490b7ce647 to your computer and use it in GitHub Desktop.
store.js
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 { createStore, applyMiddleware } from 'redux'; | |
import { persistStore, persistReducer } from 'redux-persist'; | |
import storage from 'redux-persist/lib/storage'; | |
import ReduxThunk from 'redux-thunk'; | |
import logger from 'redux-logger'; | |
import { composeWithDevTools } from 'redux-devtools-extension/developmentOnly'; | |
import rootReducer from '../reducers'; | |
const middlewares = [ReduxThunk]; | |
if (process.env.NODE_ENV === 'development') { | |
middlewares.push(logger); | |
} | |
const persistConfig = { | |
key: 'root', | |
storage, | |
}; | |
const persistedReducer = persistReducer(persistConfig, rootReducer); | |
export default () => { | |
const store = createStore( | |
persistedReducer, | |
composeWithDevTools(applyMiddleware(...middlewares)) | |
); | |
const persistor = persistStore(store); | |
return { store, persistor }; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment