Question presented to candidate: "What makes a form input controlled, and when would you deliberately leave one uncontrolled?"
What a strong answer should cover:
- Controlled: React state is the source of truth. The input has a
valueprop and anonChangethat updates state. Every keystroke is a render. - Uncontrolled: the DOM is the source of truth. The input has a
defaultValueand you read it when you need it — via a ref, or via FormData. defaultValueis the initial value only; changing it later does not move the field, which is exactly the point.- Controlled is required when something must happen per keystroke — live validation, a character counter, a dependent field, formatting as you type, or disabling submit while invalid.
- Uncontrolled is right for a plain field you only read on submit, for file inputs (which cannot be controlled), and for integrating non-React code.
- React warns about two specific mistakes: a
valuewith noonChange(a read-only field), and switching an input from uncontrolled to controlled mid-life. - React 19 Actions made uncontrolled the sensible default again — FormData collects the values, so per-field state is only needed for per-keystroke behaviour.
Clarifying questions expected:
- "Does anything need to react to each keystroke, or only to the final value?" — that is the whole decision.
- "Is this a file input?" — those are always uncontrolled.
Code / implementation expected: Optional. The two four-line versions side by side make the difference obvious.