Skip to content

Instantly share code, notes, and snippets.

@BretCameron
Created August 6, 2019 12:36
Show Gist options
  • Save BretCameron/4a184d64ae15064d36d0cc96075a9664 to your computer and use it in GitHub Desktop.
Save BretCameron/4a184d64ae15064d36d0cc96075a9664 to your computer and use it in GitHub Desktop.
Add redux-thunk middleware to your Redux store
import { createStore, applyMiddleware, compose } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers';
const initialState = {};
const middleware = [thunk];
let store;
if (window.navigator.userAgent.includes('Chrome')) {
store = createStore(rootReducer, initialState, compose(
applyMiddleware(...middleware),
window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__()
));
} else {
store = createStore(rootReducer, initialState, compose(
applyMiddleware(...middleware)
));
}
export default store;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment