What Are Uncontrolled Components?
You'll learn: The alternative approach where the DOM itself, not React state, holds form data that you access only when needed.
The Core Idea
In controlled components, React state is the single source of truth—every keystroke updates state, which updates the input. Uncontrolled components flip this model: the DOM itself manages the input's value, just like traditional HTML forms. React doesn't track changes in real-time. Instead, you use a ref to peek at the DOM element's value when you actually need it (usually on submit).
Think of it like a locked diary. With controlled components, you read every page as it's written. With uncontrolled components, the diary stays closed until you explicitly open it to read what's inside.
How It Differs
Instead of:
const [name, setName] = useState('');
// value={name} onChange={(e) => setName(e.target.value)}
You write:
const nameRef = useRef(null);
// Later: nameRef.current.value
The input manages its own value. You don't listen to onChange at all (unless you need it for other reasons). When you need the data—say, on form submission—you access nameRef.current.value.
When This Matters
Uncontrolled components avoid re-renders on every keystroke because React isn't involved in tracking changes. The input updates, but your component doesn't re-render. You retrieve the value only when necessary, like when the user clicks "Submit."
This is the classic HTML form behavior: the browser handles everything until you ask for the data.
Key Takeaway: Uncontrolled components let the DOM manage form data independently, with React accessing values via refs only when needed—avoiding per-keystroke re-renders.