When does a reducer make a multi-step UI easier to reason about?
Understand the idea, explain it in your own words and use the rubric to find your next learning gap.
The idea behind the question
A reducer expresses state transitions as a function of previous state and an action. It is useful when several fields must change together to preserve a business invariant.
A submission starts, clears an old error and locks editing. Success stores a receipt; failure restores an editable state with a message.
// Standalone transition helper; network work belongs outside it.
function reducer(state, action) {
if (action.type === 'start') return { status: 'saving', requestId: action.id };
if (action.type === 'success' && state.status === 'saving' && state.requestId === action.id) {
return { status: 'success', receipt: action.receipt };
}
return state;
}
let state = reducer({ status: 'idle' }, { type: 'start', id: 2 });
state = reducer(state, { type: 'success', id: 1, receipt: 'stale' });
console.log(state.status);
state = reducer(state, { type: 'success', id: 2, receipt: 'saved' });
console.log(state.status, state.receipt);Show expected output
saving
success savedCopy and paste to run in a separate tab. This example illustrates one concept; it is not a complete application or an automatically graded task.
A practical way to learn it
Model idle, saving, success and error states for a save button. Add a request ID and show which completion events should be ignored.
Open React project studioThe related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.
Build an explanation you understand
- State what the concept does in plain language.
- Apply it to the example and make your assumptions explicit.
- Explain a trade-off, failure case and how you would test it.
- Distinguish your actual experience from a proposed approach.
How would you explain it?
Single-question timers reset on refresh. Full mock sessions can resume from this browser.
Strengthen your explanation
Compare reasoning, not identical wording. Reference answers describe a possible approach; replace hypothetical statements with truthful details from your own work.
One way to answer
I would list the valid UI states and events before choosing an implementation. A reducer can update related fields together and make impossible combinations easier to prevent. It should remain pure; network calls belong outside the reducer and dispatch results with enough identity to reject stale responses. I would test meaningful transitions, including duplicate clicks and late responses, rather than assert every internal field assignment. A reducer is not automatically better for a single independent toggle, and an overly generic action system can make a small component harder to understand.
What a strong explanation should cover
Tick only the points your own answer addresses. This is self-assessment, not AI scoring.
0 / 3 points self-reportedWatch out for
- Starting HTTP calls from inside the reducer.
Now go one level deeper
- How would you prevent an old request from completing a newer submission?
- When is ordinary useState clearer?
Further reading
Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.