Skip to the page

Forms, testing & security · Design

Forms at scale: react-hook-form, zod and server validation

The interviewer asks

Build a 30-field KYC form (PAN, Aadhaar, address, conditional GST fields) that stays fast and validates the same way on client and server. What's your approach?

Then

Follow-ups the interviewer asks next

  1. Why is react-hook-form faster than controlled useState per field?
  2. Async validation (PAN already registered) with debounce.
  3. Multi-step wizard: where does state live, and how is it persisted on refresh?
  4. Accessibility of error messages.

The answer

What a strong answer covers

  • Uncontrolled inputs with refs mean no re-render per keystroke. zodResolver gives one schema, and z.infer gives types.
  • Share the schema with the server (Server Action or API) and always re-validate on the server.
  • Conditional fields via watch/useWatch scoped to avoid wide re-renders. shouldUnregister semantics.
  • Wizard state lives in the form context or URL step, with drafts in sessionStorage.
  • a11y: aria-invalid, aria-describedby, focus the first error, and don't rely on colour alone.

The red pen

Common traps

Avoid:validating only on the client; one giant useState object re-rendering everything.

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview