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

The Two-State Problem in Uncontrolled Inputs

Without control, input values live in the DOM separately from component state, causing sync issues.

The Two-State Problem in Uncontrolled Inputs

What you'll learn: Why uncontrolled inputs create a dangerous split between DOM state and React state.


The Split-Brain Problem

Imagine two people trying to control the same steering wheel. That's what happens with uncontrolled inputs in React.

When you don't use the value prop, the input maintains its own state internally in the DOM (what the user sees in the browser). Meanwhile, you might be tracking what you think the input contains in a React state variable. These two values can drift apart, causing bugs.

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

  return (
    <div>
      <input 
        onChange={(e) => setName(e.target.value)}
        // NO value prop - uncontrolled!
      />
      <p>State says: {name}</p>
      <button onClick={() => setName('Reset')}>
        Reset
      </button>
    </div>
  );
}

When you click "Reset", React's state changes to 'Reset', but the input field doesn't update — it still shows whatever the user typed. You now have two conflicting sources of truth: the DOM thinks the input contains one thing, React thinks it contains another.

Why This Breaks Things

Without the value prop controlling the input, you can't:

  • Programmatically reset the field
  • Enforce validation rules during typing
  • Format input as the user types
  • Sync the input with other parts of your UI reliably

The input becomes a black box that React can't manage.

Key Takeaway: Uncontrolled inputs create a two-state problem where the DOM's internal state and React's state variables fall out of sync, making the input unreliable and unpredictable. Always use the value prop to establish a single source of truth.