ReactEasy

Controlled vs Uncontrolled Forms?

In a controlled form, React state is the source of truth: each input's value comes from state and onChange updates it. In an uncontrolled form, the DOM keeps the values: inputs use defaultValue, and you read values on submit through FormData or refs. React 19 form Actions make uncontrolled forms the simplest default for many cases.

Comparison

ControlledUncontrolled
Source of truthReact statethe DOM
Value propvalue / checkeddefaultValue / defaultChecked
Read valuesfrom state, any timeon submit (FormData) or via refs
Re-render per keystrokeyesno
Live validation, formatting, dependent fieldseasyneeds extra handlers
Codemoreless
Works with server actions / progressive enhancementyesnaturally

Choosing

  • Controlled: real-time validation messages, masked inputs, fields that depend on each other, "Save" buttons enabled only when something changed.
  • Uncontrolled: simple submit-only forms, large forms where performance matters, file inputs, React 19 <form action>.
  • Hybrid via libraries: React Hook Form registers uncontrolled inputs but still provides validation and watched values.

React 19 notes

  • <form action={fn}> passes FormData to fn and resets uncontrolled fields after success; requestFormReset can reset manually.
  • useActionState returns server or validation results to show errors.

Pitfall

Switching an input from uncontrolled to controlled (value going from undefined to a string) triggers a warning; initialize state with "".

Code example

tsx
1import { useState } from "react";
2
3// Controlled: live feedback on every keystroke
4export function ControlledUsername() {
5 const [username, setUsername] = useState("");
6 const valid = /^[a-z0-9_]{3,16}$/.test(username);
7 return (
8 <form onSubmit={(e) => { e.preventDefault(); console.log(username); }}>
9 <input value={username} onChange={(e) => setUsername(e.target.value.toLowerCase())} />
10 <small>{username && !valid ? "3-16 chars: a-z, 0-9, _" : " "}</small>
11 <button disabled={!valid}>Save</button>
12 </form>
13 );
14}
15
16// Uncontrolled: read everything once, on submit (React 19 form action)
17export function UncontrolledFeedback() {
18 async function send(formData: FormData) {
19 const payload = Object.fromEntries(formData); // { rating: "5", comment: "..." }
20 await fetch("/api/feedback", { method: "POST", body: JSON.stringify(payload) });
21 }
22 return (
23 <form action={send}>
24 <select name="rating" defaultValue="5">
25 <option>5</option><option>4</option><option>3</option>
26 </select>
27 <textarea name="comment" defaultValue="" />
28 <button>Send</button>
29 </form>
30 );
31}

Practice this question

Open it in the study app to track progress, take notes, listen to the answer and work through the rest of the React set.

Open in study app