Skip to content

Instantly share code, notes, and snippets.

@onamfc
Forked from malexsan1/CreateStore.js
Created September 10, 2022 03:00
Show Gist options
  • Save onamfc/0844cdad87a25ea77a71405b402bcdd8 to your computer and use it in GitHub Desktop.
Save onamfc/0844cdad87a25ea77a71405b402bcdd8 to your computer and use it in GitHub Desktop.
Create Redux store with Saga and Loggers
import logger from 'redux-logger'
import createSagaMiddleware from 'redux-saga'
import { autoRehydrate } from 'redux-persist'
import { createStore, applyMiddleware, compose } from 'redux'
import RehydrationServices from '../'
// creates the store
export default (rootReducer, rootSaga) => {
/* ------------- Redux Configuration ------------- */
const middleware = []
const enhancers = []
/* ------------- Saga Middleware ------------- */
const sagaMiddleware = createSagaMiddleware()
middleware.push(sagaMiddleware)
/* ------------- Logger Middleware ------------- */
middleware.push(logger)
}
/* ------------- Assemble Middleware ------------- */
enhancers.push(applyMiddleware(...middleware))
/* ------------- AutoRehydrate Enhancer ------------- */
enhancers.push(autoRehydrate())
/* ------------- Create Store ------------- */
const store = createStore(rootReducer, compose(...enhancers))
/* ------------- Persistance cache busting ------------- */
// configure persistStore and check reducer version number
RehydrationServices.updateReducers(store)
// kick off root saga
sagaMiddleware.run(rootSaga)
return store
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment