Skip to the page

Component patterns · mid

Controlled vs uncontrolled components

A controlled input gets its value from React state on every keystroke; an uncontrolled input keeps its own value in the DOM and you read it on submit (ref or FormData); reusable components should support both.

The notes

What you must know

  • Controlled: <input value={v} onChange={e => setV(e.target.value)} />. React is the source of truth; easy validation and formatting as you type; one render per keystroke.
  • Uncontrolled: <input defaultValue="x" name="email" />, read with a ref or new FormData(form). Fewer renders; React 19 form actions work naturally with it.
  • React 19 resets uncontrolled forms automatically after a successful <form action>; requestFormReset resets manually.
  • Never switch: value={undefined} then value="x" gives the "uncontrolled to controlled" warning. Use value={v ?? ""}.
  • Reusable component pattern (useControllableState): if the value prop is defined, use it and call onChange; otherwise keep internal state seeded from defaultValue.
  • Large forms: react-hook-form uses uncontrolled inputs and refs, so typing does not re-render the whole form.
  • Storing derived values (like a formatted copy) in extra state is the common mistake; derive in render.

The red pen

Common traps: mistake → fix

  • Mistake: "Uncontrolled inputs are bad practice"

    Fix: they are fine and often faster; React 19 actions favour them.

  • Mistake: "value without onChange is fine"

    Fix: the input becomes read-only (React warns).

  • Mistake: "defaultValue updates when the prop changes"

    Fix: it is only the initial value; use a key to reset.

Easy to hard

Questions interviewers ask, easy to hard

  1. Controlled vs uncontrolled: what is the difference?
  2. What causes the "switching from uncontrolled to controlled" warning?
  3. Design a reusable <Dropdown> that supports both modes.
  4. Which performs better for a 50-field form, and why?
  5. How do React 19 form actions treat uncontrolled forms after submit?

Practise

Practise with these questions

Your first interview is free

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

Start your free interview