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.
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceThe 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 ornew FormData(form). Fewer renders; React 19 form actions work naturally with it. - React 19 resets uncontrolled forms automatically after a successful
<form action>;requestFormResetresets manually. - Never switch:
value={undefined}thenvalue="x"gives the "uncontrolled to controlled" warning. Usevalue={v ?? ""}. - Reusable component pattern (
useControllableState): if thevalueprop is defined, use it and callonChange; otherwise keep internal state seeded fromdefaultValue. - 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: "
valuewithoutonChangeis fine"Fix: the input becomes read-only (React warns).
Mistake: "
defaultValueupdates when the prop changes"Fix: it is only the initial value; use a
keyto reset.
Easy to hard
Questions interviewers ask, easy to hard
- Controlled vs uncontrolled: what is the difference?
- What causes the "switching from uncontrolled to controlled" warning?
- Design a reusable
<Dropdown>that supports both modes. - Which performs better for a 50-field form, and why?
- How do React 19 form actions treat uncontrolled forms after submit?
Practise
Practise with these questions
Explain it out loud
Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.
Practise by voiceYour first interview is free
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.