Loading...
Loading...
By continuing to use the platform, you accept the terms of the Privacy Policy and the use of cookies.
Redux Middleware is mechanism for extending Redux functionality that allows injecting additional logic between action dispatch and moment when it reaches reducer.
Middleware in Redux is used for:
Middleware sits between dispatch and reducer, allowing to:
const loggerMiddleware = store => next => action => {
console.log('Previous state:', store.getState());
console.log('Action:', action);
const result = next(action);
console.log('Next state:', store.getState());
return result;
};
// Connecting middleware
const store = createStore(
rootReducer,
applyMiddleware(loggerMiddleware)
);
Important:
Middleware should be used only when really necessary, as each additional middleware increases application complexity.