InterviewHubPRO
Section Overview
Q335

Question 335 of 445

Part 10: Modern React 18, React 19 & Next.js Patterns (317 - 353)

75%
React & Modern Frontend (445 Qs)•Part 10: Modern React 18, React 19 & Next.js Patterns (317 - 353)

What is Redux middleware?

Middleware provides a way to extend Redux with custom logic that runs between dispatching an action and the moment it reaches the reducer. It's the standard extension point for side effects (logging, crash reporting, async calls, analytics) since reducers themselves must stay pure and synchronous.

javascript
import { configureStore } from "@reduxjs/toolkit";

const logger = (store) => (next) => (action) => {
console.log("dispatching", action);
const result = next(action);
console.log("next state", store.getState());
return result;
};

const store = configureStore({
reducer: rootReducer,
middleware: (getDefaultMiddleware) => getDefaultMiddleware().concat(logger),
});

Common middleware includes redux-thunk (dispatch functions for async logic), redux-saga (generator-based side effects), redux-logger (action/state logging), and RTK's built-in serializable/immutable-state check middleware.