Skip to content

Instantly share code, notes, and snippets.

@Haosvit
Created April 18, 2020 10:44
Show Gist options
  • Save Haosvit/085e0b69e6115a50a69dca229f2f28dc to your computer and use it in GitHub Desktop.
Save Haosvit/085e0b69e6115a50a69dca229f2f28dc to your computer and use it in GitHub Desktop.
Redux devTools extension compose with options
import { applyMiddleware, compose, createStore } from 'redux';
import createSagaMiddleware from 'redux-saga';
import rootReducer from './rootReducer';
import rootSaga from './rootSaga';
declare global {
interface Window {
__REDUX_DEVTOOLS_EXTENSION_COMPOSE__: any;
}
}
const initialiseSagaMiddleware = createSagaMiddleware();
const composeEnhancers =
process.env.NODE_ENV !== 'production' && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({
actionSanitizer: (action) => {
const message = action.payload && action.payload.message;
return (action.type as string).endsWith('FAILURE')
? {
...action,
payload: !!message ? `(DEV) Error message: ${message}` : undefined,
}
: action;
},
})
: compose;
const enhancer = composeEnhancers(applyMiddleware(initialiseSagaMiddleware));
const store = createStore(rootReducer, enhancer);
initialiseSagaMiddleware.run(rootSaga);
export default store;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment