Courses / React 19: From Components to Production / Chapter 10
Module 5 · Forms and Data Fetching · Chapter 10 of 30
Forms: Controlled and Uncontrolled Inputs, Validation and Form Actions
Builds on State and Effects: useState, Events, useEffect and Cleanup and New in React 19: Actions, use, Optimistic UI and ref as a Prop. Next up: Data Fetching: Requests, Loading States, Races, Caching and Errors.
Part 1 · Controlled inputs: React owns the value
Who holds the value
A college admission form is mostly inputs, and every input has a value that someone has to hold. In plain HTML the input holds it, and React lets you hold it in state instead, which shapes everything else about a form.
A controlled input takes its value from props. You give it value and an onChange handler, and React makes the DOM show exactly what the state says. When the user types, the browser reports the edit, onChange runs, you store the new text in state, and the next render writes that text into the input. The state is the single source of truth, and the input is a view of it.
React's onChange runs on every edit, one call per keystroke, and the React documentation says it behaves like the browser's input event, not the change event, which for a text box waits until the field loses focus. That is what makes controlled fields useful: at every moment you know the exact text, so you can check it, reshape it or use it elsewhere on the page.
| Controlled |
|---|