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

The Standard Controlled Input Pattern

Learn the canonical pattern: value prop, onChange handler, and state variable working together.

The Standard Controlled Input Pattern

You'll learn the canonical three-part pattern that defines a controlled input in React.

The Three-Part Recipe

Every controlled input follows the same simple pattern. It's like a perfect handshake between three pieces:

  1. State variable — holds the current value
  2. value prop — displays that state on the input
  3. onChange handler — updates the state when the user types

These three always work together. Miss one, and the pattern breaks.

The Pattern in Action

const [name, setName] = useState('');

<input
  value={name}
  onChange={(e) => setName(e.target.value)}
/>

That's it. This is the standard pattern you'll write hundreds of times.

Why This Pattern Works

Think of it as a loop:

  • The input shows whatever's in name (via value)
  • User types → onChange fires
  • Handler reads e.target.value and calls setName()
  • React re-renders, input now shows the new name

State is the single source of truth. The DOM simply reflects it.

The Universal Template

Every controlled input you create follows this exact structure. Whether it's a text input, textarea, or select dropdown, the pattern stays the same: state variable, value prop, onChange handler calling setState.

You can copy this pattern, swap the state variable name, and you have a working controlled input. It's React's most common pattern for a reason—it's predictable, testable, and gives you complete control over the input's behavior.

Key Takeaway: The standard controlled input pattern is always three parts: a state variable, the value prop set to that state, and an onChange handler that updates the state with e.target.value.