Controlled Component

A controlled component is a form input whose value is driven by React state rather than the DOM. The input shows the state value, and an onChange handler updates that state on every keystroke.

React

In a controlled input, React is the single source of truth: you set the input's value prop from state and update state in onChange. This keeps the displayed value and your data perfectly in sync, and lets you validate or transform input as the user types.

The alternative is an uncontrolled component, where the DOM holds the value and you read it with a ref. Controlled components are the standard recommended approach for forms in React.

Examples

JSX — The input always displays the current state; typing updates state, which re-renders the input with the new value.

import { useState } from "react";

function NameForm() {
  const [name, setName] = useState("");
  return (
    <input
      value={name}
      onChange={(e) => setName(e.target.value)}
    />
  );
}

Learn it in a lesson

See also

Back to the Dictionary