ReactEasy

What is an uncontrolled component?

An uncontrolled component is a form element that keeps its own value in the DOM instead of in React state. You set a starting value with defaultValue (or defaultChecked) and read the current value when needed, from a ref or, more commonly in React 19, from the FormData passed to a form action.

How to read values

  • Form actions (React 19): <form action={(formData) => ...}> gives you formData.get("email") on submit. No state, no refs.
  • onSubmit + new FormData(e.currentTarget).
  • Refs: inputRef.current.value for one-off reads.
  • File inputs are always uncontrolled: their value can only be read from the DOM (input.files).

Pros

  • Less code and no re-render per keystroke, so large forms stay fast.
  • Works naturally with progressive enhancement and server actions.
  • Easy integration with non-React libraries that manage the DOM.

Cons

  • No instant validation or formatting without extra listeners.
  • Harder to keep multiple fields in sync or to reset to dynamic values (change the form's key, or call form.reset(); React 19 resets forms automatically after a successful action).

Choosing

Use uncontrolled inputs for simple forms submitted as a whole, and controlled inputs when the UI must react to every change. React Hook Form is uncontrolled by design for performance, with validation layered on top.

Rule

Do not mix value and defaultValue on the same input.

Code example

tsx
1import { useRef } from "react";
2
3// React 19: uncontrolled inputs + a form action
4export function NewsletterForm() {
5 async function subscribe(formData: FormData) {
6 const email = String(formData.get("email"));
7 await fetch("/api/subscribe", { method: "POST", body: JSON.stringify({ email }) });
8 // React resets the form after the action completes
9 }
10
11 return (
12 <form action={subscribe}>
13 <input name="email" type="email" defaultValue="" required />
14 <button>Subscribe</button>
15 </form>
16 );
17}
18
19// Refs: read the DOM value on demand (file inputs are always uncontrolled)
20export function AvatarUpload() {
21 const fileRef = useRef<HTMLInputElement>(null);
22 const upload = () => {
23 const file = fileRef.current?.files?.[0];
24 if (file) console.log("uploading", file.name, file.size);
25 };
26 return (
27 <>
28 <input type="file" ref={fileRef} accept="image/*" />
29 <button onClick={upload}>Upload</button>
30 </>
31 );
32}

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