Redux and Redux Toolkit interview questions and answers
Redux interview questions test whether you understand the one-way data flow behind it: a single store, plain action objects, pure reducers that return new state, middleware for side effects, and selectors that read state without causing needless re-renders. Most teams now write Redux Toolkit, so expect createSlice, createAsyncThunk, entity adapters and RTK Query, plus the honest question of when an app does not need Redux at all.
By Evin JohnPublished 9 min read
How Redux questions are asked
Redux comes up in React interviews at companies with large client-side apps: dashboards, trading screens, editors and admin tools where many components read and change shared state. Interviewers rarely want API trivia. They ask you to explain the data flow, write or fix a reducer, spot a component that re-renders on every dispatch, and justify where server data should live. A classic live exercise is to implement a tiny createStore, or a middleware, from scratch.
| Format | What you do | What earns credit |
|---|---|---|
| Concept questions | Explain the flow from a click to a re-render. | Naming dispatch, reducer, new state, subscription and selector in order, without hand-waving. |
| Write from scratch | Implement createStore, a thunk middleware or a memoized selector in plain JavaScript. | Correct closures, returning unsubscribe, and not mutating state. |
| Fix the bug | A reducer mutates state, or a selector returns a new array each time. | Seeing why the UI does not update, or updates too often, and the minimal fix. |
| Architecture talk | How you would structure state for a large app. | Slices by feature, normalized entities, server cache separate from UI state. |
Fundamentals: store, actions and reducers
- What problem does Redux solve? Shared state that many distant components read and change. It puts that state in one place and makes every change an explicit, logged event, which makes changes traceable and easy to debug.
- What are the three principles? A single source of truth in one store, state that is read-only and changed only by dispatching actions, and changes made by pure reducer functions.
- What is an action? A plain object describing what happened, with a type string such as
todos/addedand usually a payload. Name it as an event, not as a setter. - Why must a reducer be pure? Given the same state and action it must return the same result, with no API calls, random values or dates. That makes time-travel debugging, replays and tests possible.
- Why not mutate state in a reducer? Redux and React-Redux detect changes by reference. A mutated object keeps the same reference, so subscribers think nothing changed and the UI goes stale.
- What does combineReducers do? Builds a root reducer that hands each key of the state object to its own slice reducer, so each feature manages its own part.
- What happens when you call dispatch? The root reducer runs with the current state and the action, the store saves the returned state, and every subscriber is notified. React-Redux then runs each component's selector and re-renders only those whose result changed.
- What do the Redux DevTools give you? A log of every action with the state before and after, diffs, and the ability to jump back to an earlier state. It only works well when actions and state are plain, serializable data.
- Is Redux only for React? No. The core is plain JavaScript and works with any UI; React-Redux is the binding layer that adds hooks such as useSelector and useDispatch.
function createStore(reducer, preloadedState) {
let state = preloadedState;
const listeners = new Set();
function dispatch(action) {
state = reducer(state, action);
listeners.forEach((listener) => listener());
return action;
}
function subscribe(listener) {
listeners.add(listener);
return () => listeners.delete(listener);
}
dispatch({ type: '@@init' });
return { getState: () => state, dispatch, subscribe };
}
function todos(state = [], action) {
switch (action.type) {
case 'todos/added':
return [...state, { id: action.payload.id, text: action.payload.text, done: false }];
case 'todos/toggled':
return state.map((t) => (t.id === action.payload ? { ...t, done: !t.done } : t));
default:
return state;
}
}
const store = createStore(todos);
let notified = 0;
store.subscribe(() => notified++);
store.dispatch({ type: 'todos/added', payload: { id: 1, text: 'Write tests' } });
const before = store.getState();
store.dispatch({ type: 'todos/toggled', payload: 1 });
console.log(store.getState()[0].done, before[0].done, notified); // true false 2The second number is the point to say out loud: the old state still reads false because the toggle built a new array and a new todo object instead of changing the old ones. That is what lets a component compare references and know something changed.
Middleware and async logic
const thunk = ({ dispatch, getState }) => (next) => (action) =>
typeof action === 'function' ? action(dispatch, getState) : next(action);
const log = [];
const logger = () => (next) => (action) => {
log.push(action.type);
return next(action);
};
function applyMiddleware(store, ...middlewares) {
let dispatch = () => { throw new Error('Dispatching while building middleware'); };
const api = { getState: store.getState, dispatch: (action) => dispatch(action) };
dispatch = middlewares
.map((mw) => mw(api))
.reduceRight((next, mw) => mw(next), store.dispatch);
return { ...store, dispatch };
}
// a tiny base store so this file runs on its own
let state = 0;
const base = {
getState: () => state,
dispatch: (action) => { if (action.type === 'add') state += action.payload; return action; },
};
const store = applyMiddleware(base, thunk, logger);
store.dispatch((dispatch, getState) => {
dispatch({ type: 'add', payload: 2 });
if (getState() < 5) dispatch({ type: 'add', payload: 3 });
});
console.log(store.getState(), log); // 5 [ 'add', 'add' ]| Question | What it tests | What a strong answer shows |
|---|---|---|
| Explain the store, next, action signature. | Middleware model | Each middleware gets the store API once, then the next dispatch in the chain, and returns its own dispatch. Calling next passes the action on; calling store dispatch starts again from the top. |
| Why does the logger never see the thunk function? | Chain order | thunk comes first, catches the function and runs it. The plain actions the thunk dispatches go through the full chain from the start, so the logger sees each add. |
| Where should an API call live? | Side effects | Not in a reducer. In a thunk, a listener, a saga, or a data-fetching layer such as RTK Query, which then dispatches the result. |
| Thunks, sagas or the listener middleware? | Tool choice | Thunks cover most request flows simply. Sagas suit complex long-running workflows and cancellation but add generator code. The listener middleware in Redux Toolkit reacts to actions with less ceremony than sagas. |
| What does createAsyncThunk generate? | Async lifecycle | One thunk plus pending, fulfilled and rejected action types. Reducers handle those to track loading and errors, and it passes an AbortSignal so a request can be cancelled. |
| How do you avoid race conditions in search requests? | Concurrency | Abort the previous request, or record the requestId from pending and ignore fulfilled results that are not the latest. |
Redux Toolkit questions
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit';
export const fetchTodos = createAsyncThunk('todos/fetch', async (_, { signal }) => {
const res = await fetch('/api/todos', { signal });
if (!res.ok) throw new Error('Failed to load');
return res.json();
});
const todosSlice = createSlice({
name: 'todos',
initialState: { items: [], status: 'idle', error: null },
reducers: {
todoToggled(state, action) {
const todo = state.items.find((t) => t.id === action.payload);
if (todo) todo.done = !todo.done; // Immer turns this into an immutable update
},
},
extraReducers: (builder) => {
builder
.addCase(fetchTodos.pending, (state) => { state.status = 'loading'; })
.addCase(fetchTodos.fulfilled, (state, action) => {
state.status = 'succeeded';
state.items = action.payload;
})
.addCase(fetchTodos.rejected, (state, action) => {
state.status = 'failed';
state.error = action.error.message;
});
},
});
export const { todoToggled } = todosSlice.actions;
export default todosSlice.reducer;- Why is mutating code allowed inside createSlice? The reducer receives an Immer draft. Immer records the changes and produces a new immutable state, sharing untouched parts. Either mutate the draft or return a new value, not both.
- What does configureStore set up for you? It combines slice reducers, adds the thunk middleware, enables the Redux DevTools, and in development adds checks that warn about mutations and non-serializable values in state or actions.
- Why should state and actions be serializable? DevTools, persistence and time travel depend on it. Dates, class instances, promises and functions in state break those tools and hide bugs.
- What does createEntityAdapter give you? A normalized shape with ids and entities, ready-made reducers to add, update and remove, and sorted selectors. Lookups by id become constant time and updates touch one entity.
- What is RTK Query and when would you use it? A data-fetching and caching layer built into Redux Toolkit. You define endpoints, it generates hooks, de-duplicates requests, caches results and refetches when tagged data is invalidated after a mutation.
- How do tags work in RTK Query? Queries provide tags such as a list or an item id, mutations invalidate tags, and any active query that provided an invalidated tag refetches.
Selectors, performance and senior questions
function createSelector(input, compute) {
let called = false;
let lastInput;
let lastResult;
return (state) => {
const value = input(state);
if (called && value === lastInput) return lastResult;
called = true;
lastInput = value;
lastResult = compute(value);
return lastResult;
};
}
const selectOpenTodos = createSelector(
(state) => state.todos,
(todos) => todos.filter((t) => !t.done),
);
const s1 = { todos: [{ id: 1, done: false }, { id: 2, done: true }], filter: 'all' };
const s2 = { ...s1, filter: 'open' }; // todos array unchanged
console.log(selectOpenTodos(s1) === selectOpenTodos(s2)); // true: same array, no re-render| Question | What it tests | What a strong answer shows |
|---|---|---|
| When does useSelector cause a re-render? | React-Redux | After every dispatch it runs the selector and compares the result with the previous one by reference. A selector that builds a new array or object each time re-renders the component on every action. |
| How do you fix a selector that filters inline? | Memoization | Use createSelector so the derived array is reused while inputs are unchanged, select smaller primitive values, or pass shallowEqual for a small object. |
| Why normalize state? | State shape | Nested copies of the same entity drift out of sync and make updates deep and slow. Storing entities by id once and referencing ids keeps one copy and simple updates. |
| Should server data live in Redux? | Server versus client state | Cached server data has different needs: staleness, refetching, de-duplication. A cache layer such as RTK Query handles them; Redux slices then hold true client state like filters and drafts. |
| Redux or React context? | Tool choice | Context passes a value down but every consumer re-renders when it changes, and it has no middleware or devtools story. It suits rarely changing values like theme. Redux suits frequently updated shared state with many readers. |
| Form state in Redux? | Judgment | Usually not. Keystroke-level state belongs in the component or a form library. Put the submitted result, or a draft that must survive navigation, in the store. |
| How would you migrate legacy Redux to Redux Toolkit? | Migration | Swap createStore for configureStore first, then convert one reducer at a time to createSlice, keeping action types compatible. Replace hand-written fetch logic with RTK Query where it fits. |
| How do you test Redux code? | Testing | Reducers and selectors as pure functions with plain inputs. Thunks and components through integration tests with a real store and a mocked network, rather than mocking the store itself. |
| Scenario: the app slows down as the list grows to thousands of rows. | Diagnosis | Profile, then check selectors that rebuild arrays, components subscribed to the whole list instead of one row by id, and missing list virtualization. |
Fictional example
- Our admin app kept every API response in Redux with hand-written loading flags: about forty slices, and a lot of bugs where one screen showed stale data after another edited it. I proposed moving server data to RTK Query, one feature at a time, starting with the orders list. We defined tags for orders and invalidated them from the edit mutation, which removed the stale screen bug class for that feature. The orders slice shrank to filters and selection. Over the next quarter the team migrated most features, and new screens stopped needing loading reducers at all. The lesson I took was to separate cached server data from UI state early.
Redux preparation in five sessions
- Session 1: from scratchWrite createStore, combineReducers and a thunk middleware without looking. Then run the snippets on this page and compare.
- Session 2: immutabilityWrite five nested updates by hand with spread syntax, then the same with createSlice, and explain what Immer does.
- Session 3: asyncBuild a search with createAsyncThunk that aborts stale requests and shows loading and error states.
- Session 4: performanceMake a component re-render on every dispatch with an inline filter, confirm it in the React Profiler, and fix it with a memoized selector.
- Session 5: architectureSketch the state of an app you know: which parts are server cache, which are client state, and which do not belong in Redux at all.
Hooks, rendering and effects are covered in React interview questions. A different take on reactive state, compiled instead of dispatched, is in Svelte interview questions. For the full role, see frontend developer interview questions.
Natively, an AI interview assistant for Mac and Windows, can support your Redux practice. It records a transcript of each mock round so you can see whether you explained reference equality or just said it re-renders. In practice it can read a reducer bug from a screenshot and suggest where to look, and on Pro or the free trial it brings in your résumé and the job description. Earlier sessions and notes remain for review.
Questions people ask
What Redux questions are asked in interviews?
The data flow from dispatch to re-render, pure reducers and immutability, middleware and thunks, Redux Toolkit createSlice and createAsyncThunk, normalized state, memoized selectors, RTK Query and when Redux is not needed.
Why must Redux reducers be pure?
So the same state and action always give the same result with no side effects. That keeps updates predictable, testable and replayable, and returning new objects lets components detect changes by reference.
What is the difference between Redux and Redux Toolkit?
Redux Toolkit is the official way to write Redux. It wraps the core with configureStore, createSlice with Immer, createAsyncThunk, entity adapters and RTK Query, removing most hand-written boilerplate.
Is Redux still asked about in React interviews?
Often, at companies with large client-side apps. Expect questions on Redux Toolkit and on when context, local state or a data-fetching cache would be a better fit than a global store.
Where to go next
Practice with the same assistant you would use on a call: it listens, transcribes and suggests answers from your own resume and the job description.
Facts on this page were last checked on . Product details come from the Natively app itself; if something here is out of date, tell us at hello@heynatively.com.
