DEV Community

Cover image for How to write redux middleware - sample code snippet
Manu Krishnan
Manu Krishnan

Posted on

How to write redux middleware - sample code snippet

Here is a sample snippet where you can add your logic to the redux middleware (this snippet will just console all your actions)

const logMiddleWare = store => next => action => {
// Replace your logic below
console.log(action.type, action);
next(action);
}

Here is how it should be included in your store

const Store = createStore(rootReducer, applyMiddleware(thunk, logMiddleWare));

Top comments (0)