A reducer is a pure function responsible for handling actions and returning a new state based on the previous state and the action that was dispatched.
A reducer is a function that receives the current state and an action object, decides how to update the state if necessary, and returns the new state: (state, action) => newState.
You can think of a reducer as an event listener that handles events based on the received action (event) type.
They should only calculate the new state value based on the current state and action arguments.
They are not allowed to modify the existing state. Instead, they must make immutable updates, by copying the existing state and making changes to the copied values.
They must not do any asynchronous logic, calculate random values, or cause other "side effects" that is they must be pure functions
You need to add a new piece of UI that toggles a boolean flag in the Redux store. How would you write the reducer for that flag?
If an action with type 'INCREMENT' is dispatched but your reducer forgets to handle it, what will the state look like afterwards?
While implementing a shopping cart feature, the cart total sometimes becomes stale after removing an item. Walk me through how you would debug the reducer responsible for the cart state.
We want to split a large reducer into smaller ones for maintainability. What trade‑offs do you consider when using combineReducers versus a hand‑rolled switch statement?
Our application now stores a deeply nested user profile object. Updating a nested field caused performance regressions. How would you refactor the reducer to minimize unnecessary re‑renders?
Explain how you would design a reducer strategy to support optimistic UI updates and rollback on server errors.
We are migrating several legacy modules from Redux to a new state‑management library. What approach would you take to gradually replace reducers while keeping the app stable?
At scale, many teams own separate slices of the store. How would you enforce consistent reducer patterns and prevent accidental state shape changes across teams?