Question presented to candidate: "Walk me through building a form in React. Controlled or uncontrolled, and how has React 19 changed this?"
What a strong answer should cover:
- Controlled: the input
valuecomes from state and every keystroke goes throughonChange. React state is the source of truth. - Uncontrolled: the DOM holds the value; you read it on submit with a ref or
FormData.defaultValueseeds it. - Controlled is the default because it enables live validation, conditional enabling, and formatting as you type — at the cost of a re-render per keystroke.
- Uncontrolled is genuinely better for large or simple forms where you only need values at submit time;
FormDatareads the whole form with no state at all. - React 19 additions: a function passed to
<form action>, plususeActionStatefor the result and pending state, anduseFormStatusfor a child to read the parent form's pending state. useFormStatusships fromreact-dom, notreact.- Always give inputs a
name— that is whatFormDataand form actions key off. - For anything non-trivial, a form library (React Hook Form, TanStack Form) exists because validation, arrays, and error handling get repetitive.
- Accessibility: label association, and errors announced rather than only coloured.
Clarifying questions expected:
- "Do we need validation as the user types, or only on submit?" — that decides controlled versus uncontrolled.
- "Are we on React 19 with a framework, so form actions are available?"
Code / implementation expected: Yes — a controlled field and an uncontrolled form read via FormData.