The final task in Store.ts is to create a function that creates the store. Let's do this by carrying out the following steps:
- First, let's import the Store type and createStore and applyMiddleware functions from Redux, along with the thunk object from Redux Thunk:
import {
Action,
ActionCreator,
Dispatch,
Reducer,
combineReducers,
Store,
createStore,
applyMiddleware
} from 'redux';
import thunk, { ThunkAction } from 'redux-thunk';
- Let's create a function to create the store:
export function configureStore(): Store<AppState> {
const store = createStore(
rootReducer,
undefined,
applyMiddleware(thunk)
);
return store;
}
This function uses the createStore function from Redux by passing in the combined reducers, undefined as the initial state, and the Thunk middleware using the applyMiddleware function...