Skip to content

Instantly share code, notes, and snippets.

@jasonleehodges
Created March 21, 2020 22:21
Show Gist options
  • Save jasonleehodges/623f9adccc8ca5a620dd5404438383c6 to your computer and use it in GitHub Desktop.
Save jasonleehodges/623f9adccc8ca5a620dd5404438383c6 to your computer and use it in GitHub Desktop.
Configure Redux Store
import { AnyAction, applyMiddleware, compose, createStore } from 'redux';
import combinedReducers, { RootState } from '../reducers';
import thunk, { ThunkMiddleware } from 'redux-thunk';
const devToolsCompose = (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__;
const composeEnhancers = (devToolsCompose !== null && devToolsCompose !== undefined)
? devToolsCompose
: compose;
export type ThunkWithRootState = ThunkMiddleware<RootState, AnyAction>;
const reduxStore = (initialState: RootState = {} as RootState) => {
return createStore(
combinedReducers,
initialState,
composeEnhancers(
applyMiddleware(thunk as ThunkWithRootState)
),
);
}
export default reduxStore;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment