thunkMiddleware - rootstrap/redux-tools GitHub Wiki
The thunkMiddleware is what enables thunks created with createThunk to behave as expected, dispatching success, and error functions when it corresponds.
Configuration:
import { applyMiddleware, compose, createStore } from 'redux';
import { thunkMiddleware } from '@rootstrap/redux-tools';
import rootReducer from './reducers';
export default function configureStore(preloadedState) {
const middlewareEnhancer = applyMiddleware(thunkMiddleware);
const enhancers = [middlewareEnhancer];
const composedEnhancers = compose(...enhancers);
const store = createStore(rootReducer, preloadedState, composedEnhancers);
return store;
}
The middleware has an option to parse responses and errors for you. Following the previous example, you can use this functionality like this:
import { thunkMiddleware } from '@rootstrap/redux-tools';
const thunkWithParsing = thunkMiddleware.withConfig({
parseError: youPraseErrorFunction,
praseResponse: yourParseResponseFunction
})
const middlewareEnhancer = applyMiddleware(thunkWithParsing);