Interview questions with answers
Redux interview questions and answers
Single store, actions, reducers, middleware and immutability. Open any question to read its model answer; the multiple-choice set marks the right option and explains it.
- Subjective
- 30
- Objective
- 30
Subjective questions 30
1What are Redux's three principles?Asked almost every time
A single source of truth: the whole app state lives in one store. State is read-only: the only way to change it is to dispatch an action, a plain object describing what happened. Changes are made with pure functions: reducers take the previous state and an action and return the next state without side effects.
2Explain the Redux data flow.Asked almost every time
A UI event dispatches an action. The store calls the root reducer with the current state and the action; reducers return a new state. The store notifies subscribers, and UI bound with useSelector re-renders where its selected data changed. Middleware sits between dispatch and the reducer for side effects.
3Why must reducers be pure and state immutable?Asked almost every time
Purity makes results predictable and testable, and enables time-travel debugging and replay. Immutability lets Redux and React detect changes cheaply by reference (prev !== next) instead of deep comparison; mutating state in place hides changes and causes stale UI. Redux Toolkit uses Immer so you can write mutating-looking code safely.
4What is middleware and give examples?Asked almost every time
Middleware wraps dispatch, seeing every action before it reaches reducers. It handles side effects and cross-cutting concerns: redux-thunk lets you dispatch functions for async logic, redux-saga uses generators for complex flows, redux-observable uses RxJS, and loggers or crash reporters observe actions. RTK includes the thunk and listener middleware.
5How does Redux fit with React in practice?Asked almost every time
The store is created once and provided with <Provider store>. Components read slices with useSelector and send actions with useDispatch. Reducers compute the next state, and subscribed components re-render when their selected values change.
6How do you handle async logic in Redux?Asked almost every time
Reducers must be pure, so side effects go in middleware: thunks (functions that dispatch actions before and after a request), sagas, observables or the listener middleware. Redux Toolkit's createAsyncThunk and RTK Query cover most cases.
7Why should Redux state be serialisable?Asked almost every time
Plain serialisable data makes time-travel debugging, persistence, logging and server rendering reliable. Promises, class instances, functions or Maps break DevTools and persistence, so keep them out of state and actions.
8How do useSelector and useDispatch work?Very often asked
useSelector(selector) reads data from the store and re-renders the component when the selected value changes by reference equality. useDispatch() returns the store's dispatch function. Keep selectors small and return stable references; avoid creating new objects in selectors without memoisation.
9What are memoised selectors and why use reselect?Very often asked
createSelector builds selectors that cache their result and recompute only when inputs change. They avoid repeating expensive derivations and keep returned references stable, preventing needless re-renders. Keep state minimal and derive the rest with selectors.
10How do you structure Redux state?Very often asked
Normalise data: store entities by ID in lookup tables ({ ids: [], entities: {} }) instead of nested arrays, split state into slices by feature, keep server cache separate (RTK Query), and keep UI-only state local unless it is shared.
11When should you not use Redux?Very often asked
When state is simple or local, when most state is server data (use a data-fetching library), or when the team does not need its structure. Context, component state or a lighter store may be enough. Redux shines with complex shared client state, many contributors and strong debugging needs.
12What is the modern recommended way to write Redux?Very often asked
Redux Toolkit: configureStore, createSlice with Immer-powered reducers, createAsyncThunk or RTK Query for data, TypeScript-typed hooks, and React-Redux hooks rather than connect. Hand-written action types, switch reducers and createStore are legacy.
13What is the difference between local state and Redux state?Very often asked
Local state (useState) suits data used by one component or a small subtree, such as an open dropdown. Redux suits data shared widely, needed after navigation, or updated from many places. Not everything belongs in Redux.
14How do you avoid unnecessary re-renders with useSelector?Very often asked
Select the smallest value needed, avoid creating new objects or arrays in selectors, use memoised selectors (createSelector) for derived data, or pass shallowEqual as the equality function when selecting several fields.
15What is the ducks pattern?Very often asked
Keeping a feature's action types, action creators and reducer in one file. Redux Toolkit's createSlice formalises it, now usually organised as feature folders.
16How do you persist Redux state?Very often asked
Use redux-persist to save chosen slices to storage and rehydrate on load, with a whitelist or blacklist, versioning and migrations. Avoid persisting server data that should be refetched.
17How do you test reducers and selectors?Very often asked
Reducers are pure: call them with a state and action and assert the result. Selectors are pure too: pass a sample state. For connected components, render with a real store created per test rather than mocking the store.
18What is the listener middleware?Very often asked
An RTK middleware that runs effects in response to actions or state changes (startListening({ actionCreator, effect })), with async support and cancellation. It is a lighter alternative to sagas for reactive logic.
19How does time-travel debugging work?Often asked
Because every change is an action applied by pure reducers, Redux DevTools records the action log and state snapshots. You can step back and forward through actions, inspect diffs, and replay or skip actions to reproduce bugs.
20Explain combineReducers.Often asked
It builds a root reducer from an object of slice reducers; each slice reducer receives only its part of the state and every action, and the results are combined into the new root state. Each key becomes a top-level state field.
21Thunks vs. sagas?Often asked
A thunk is a function dispatched as an action that receives dispatch and getState, good for straightforward async calls. Sagas use generator functions and effects to orchestrate complex flows such as cancellation, debouncing, races and background tasks, at the cost of more concepts. RTK's listener middleware covers many saga use cases.
22What are action types and why are they strings?Often asked
Each action has a type describing what happened ('todos/added'). Strings are serialisable and readable in DevTools and logs. The convention is domain/eventName, describing events rather than setters.
23How do you code-split reducers?Often asked
Inject reducers when their feature loads, for example with combineSlices and inject in Redux Toolkit 2, so the initial bundle includes only the reducers needed at startup.
24How does Redux relate to the Flux architecture?Often asked
Redux is inspired by Flux's one-way data flow, but uses a single store and pure reducer functions instead of several stores and a dispatcher, which makes state changes easier to trace.
25What is the role of the root reducer?Often asked
The single reducer passed to the store, usually built with combineReducers from feature reducers. It can also handle global actions like logout by resetting state.
26Why do actions describe events rather than setters?Often asked
Names like 'order/submitted' record what happened, so several reducers can respond and the history in DevTools reads like a log of user activity, whereas 'setLoading' style actions scatter logic across components.
27What problems led to Redux Toolkit?Often asked
Classic Redux required lots of boilerplate (constants, action creators, switch statements), manual immutable updates that were easy to get wrong, and assembling many packages for a typical setup. RTK bundles good defaults.
28What is the connect function?Sometimes asked
The older React-Redux API: a higher-order component taking mapStateToProps and mapDispatchToProps to inject state and action creators as props. Hooks have replaced it in new code.
29What is an action creator?Sometimes asked
A function that returns an action object, such as addTodo(text) => ({ type: 'todos/added', payload: text }), so actions are created consistently. createSlice generates them automatically.
30What is the difference between Redux and MobX?Sometimes asked
Redux uses explicit actions, pure reducers and immutable updates with a single store. MobX uses observable state that you mutate directly, with automatic tracking of what components use. MobX is less code; Redux is more explicit and traceable.
Objective questions 30
1How is state changed in Redux?Asked almost every time
Why: Actions are the only way to trigger changes.
2A reducer must be…Asked almost every time
Why: Same input, same output, no side effects.
3Which hook reads data from the store?Asked almost every time
Why: useSelector subscribes to selected state.
4Which component makes the store available to React?Asked almost every time
Why: From react-redux.
5Where should side effects go in Redux?Asked almost every time
Why: Reducers must stay pure.
6What should never be put in Redux state?Asked almost every time
Why: Breaks DevTools and persistence.
7What does middleware intercept?Very often asked
Why: It wraps dispatch.
8Which middleware lets you dispatch functions?Very often asked
Why: Thunks receive dispatch and getState.
9What does createSelector provide?Very often asked
Why: Reselect caches results by input.
10Why is immutability important in Redux?Very often asked
Why: New references signal changes.
11Which selector pattern causes re-renders every time?Very often asked
Why: New references fail equality.
12Which library saves Redux state to storage?Very often asked
Why: Rehydrates on load.
13How should a reducer be tested?Very often asked
Why: Reducers are pure functions.
14Which RTK middleware runs effects in response to actions?Very often asked
Why: startListening.
15Which naming convention is recommended for action types?Very often asked
Why: Describe events.
16What does combineReducers do?Often asked
Why: Each key maps to a slice reducer.
17Normalised state stores entities…Often asked
Why: Lookup by ID avoids duplication.
18Which tool enables time-travel debugging?Often asked
Why: It records actions and states.
19What is the recommended way to write Redux today?Often asked
Why: RTK is the official approach.
20Which state is best kept local?Often asked
Why: Not everything belongs in Redux.
21Which equality function compares selected objects field by field?Often asked
Why: Exported by react-redux.
22Which RTK 2 function supports injecting slices later?Often asked
Why: Code-split reducers.
23Redux was inspired by…Often asked
Why: One-way data flow.
24The root reducer is…Often asked
Why: Usually from combineReducers.
25The ducks pattern keeps… together.Often asked
Why: createSlice formalises it.
26An action is…Sometimes asked
Why: Usually { type, payload }.
27Which library uses generator functions for side effects?Sometimes asked
Why: Sagas yield effects.
28The older API to connect components to the store is…Sometimes asked
Why: connect is a higher-order component.
29MobX differs from Redux by using…Sometimes asked
Why: Automatic tracking.
30Which created the original Redux?Sometimes asked
Why: Released in 2015.
Track what you have practised and search every bank in your dashboard.
Start learning