KatInterview

Build a Three-Stage Signup Wizard with React Reducer State

Data Structure DesignModel answer
MediumModel answerData Structure DesignreactformsuseReducer

Last updated

Design a React wizard with profile, address and review stages, covering validation, guarded navigation, disabled controls, a submit spinner and server error display, plus scaling and performance trade-offs.

Build a React component that implements a three-stage wizard for collecting a user's details.

Stages

  1. Profile: the user's basic personal information (for example name and email).
  2. Address: street, city and postal code.
  3. Review: a read-only summary of everything entered, with a button to confirm and send.

Functional requirements

  • Each field has simple validation (required values, a plausible email format, a postal code pattern).
  • The user can move forward, move back, and jump between stages using a step indicator.
  • Controls must be enabled or disabled sensibly. For example, the user must not be able to skip past invalid stages or trigger a second submission while one is in flight.
  • While the final submission is pending, show a loading state.
  • If the submission fails, show a clear error message and let the user retry without losing their data.

Expected deliverable

Write the component (the submit handler is passed in as an async prop that may reject). Be prepared to discuss:

  • Why you would manage the wizard with a reducer rather than several independent useState hooks.
  • How you would structure the code as the number of stages grows large.
  • How to design error messages so they are friendly to users yet simple to reason about in code.
  • Which performance optimizations are worth applying (memoization, lazy rendering, and so on).

Hints

Hint 1

Model the wizard as a small state machine: current step, all field values, which fields were touched, a submit status (idle, submitting, error, success) and the server error message, all in one reducer.

Hint 2

Describe the stages with a config array (title and field list) and keep validation a pure function of the values. Derive disabled flags, visible errors and the spinner from state instead of storing them separately.

Hint 3

Put navigation guards in the reducer: Next only advances if the current stage validates, jumping to stage k requires every earlier stage to be valid, and a submit action is ignored while already submitting. Show a field's error only after it has been touched.