When does a reducer make a multi-step UI easier to reason about?

React state & reliabilityTechnical deep diveAbout 10 minutes

Understand the idea, explain it in your own words and use the rubric to find your next learning gap.

Local drafts · no account or AI calls
Sukoaa original

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.

AN ILLUSTRATIVE EXAMPLE

A submission starts, clears an old error and locks editing. Success stores a receipt; failure restores an editable state with a message.

TRY A SMALL EXAMPLEJavaScript · standalone helper
// 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 saved
Open JavaScript playground

Copy 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 studio

The related tool opens separately; your interview answer stays here. Written practice is self-guided, without automatic code grading.

Build an explanation you understand

  1. State what the concept does in plain language.
  2. Apply it to the example and make your assumptions explicit.
  3. Explain a trade-off, failure case and how you would test it.
  4. Distinguish your actual experience from a proposed approach.

Further reading

Further-reading links support learning; the reference is Sukoaa-authored, not an official employer answer key.