Course contentsShow
← React
Lesson 465 of 2,39613. Controlled ComponentsFree lesson

Controlled: State Drives the DOM

Setting value={state} makes React state the only place the current value exists.

Controlled: State Drives the DOM

What you'll learn: How React state becomes the ultimate authority over what appears in your input fields.


When you set value={state} on an input, you're doing something powerful: you're making React state the single, authoritative source of what that input displays. The DOM no longer decides what's in the input box — React does.

The Flow of Control

In a controlled component, the relationship works like this:

  1. State holds the current value (e.g., const [name, setName] = useState(''))
  2. The input displays that state (<input value={name} />)
  3. User types something
  4. onChange fires, updating state
  5. React re-renders, feeding the new state back to value
  6. The DOM updates to match state

The DOM never acts independently. It only shows what state tells it to show.

Why This Matters

Without value={state}, the input maintains its own internal value separate from your React state. You'd have two sources of truth: one in the DOM, one in your state variable. They can drift apart, creating bugs.

With value={state}, there's only one truth: your React state. The DOM becomes a mirror of that state, not a separate entity.

The Analogy

Think of state as the script for a play, and the DOM as the actors on stage. In a controlled component, the actors (DOM) can only say lines that are written in the script (state). Even if an audience member (user) shouts something, the actors must wait for that shout to be written into the script before they can repeat it.

Key Takeaway: Setting value={state} makes React state the single source of truth — the DOM displays exactly what state contains, nothing more, nothing less.