The setState → Re-render → DOM Update Flow
What you'll learn: How every keystroke in a controlled input triggers a complete React update cycle.
The Three-Step Dance
When you type in a controlled input, React performs a precise sequence:
setStateis called — YouronChangehandler capturesevent.target.valueand calls the state setter- Component re-renders — React executes your component function again with the new state value
- DOM updates — React compares the virtual DOM and syncs the changed
valueprop back to the actual input element
Why This Matters
This is why controlled components feel "responsive" — the flow happens so fast it's invisible to users. Type the letter "a":
// Step 1: onChange fires
<input value={text} onChange={(e) => setText(e.target.value)} />
// User types "a" → setText("a") is called
// Step 2: Component re-renders with text = "a"
function MyComponent() {
const [text, setText] = useState(""); // now returns "a"
return <input value={text} ... />; // value prop is now "a"
}
// Step 3: React updates the DOM
// The input's value attribute becomes "a"
Each keystroke repeats this entire cycle. This is the "single source of truth" in action — state flows down to the DOM, never the reverse.
The Synchronization Loop
Think of it like a mirror: the input reflects what's in state, and every change bounces back through state before appearing in the DOM. You're never reading directly from the DOM — you're always reading from React state.
Key Takeaway: Every character typed triggers setState → re-render → DOM sync. This complete round-trip ensures React state remains the authoritative source for the input's value.