Skip to content
IT glossary
FrontendUpdated December 3, 2026

Controlled component

Контролируемый компонент

A controlled component displays a value supplied by application code. In React, an editable field reports user input through an event handler, and the application supplies the value the field should display next.

What makes a component controlled?

Suppose a search box has a Clear button. React can clear the box by rendering it with value=""; the button doesn't need to reach into the DOM. That's a controlled input: the application owns the current value and passes it to the field. The value might come from local React state or from a parent component that shares it with other parts of the page.

An uncontrolled input works differently. The browser keeps track of the current text. You can supply a starting value with defaultValue and read the submitted value with FormData. You can even listen for changes without controlling the field. The deciding factor is who supplies the current value, not whether there's an event handler.

How updates work

For a text input, React's onChange handler runs as the user edits the text. The handler reads event.target.value and queues a state update right away. React then renders the input with the updated value. A checkbox follows the same pattern, but checked controls whether it's selected, and event.target.checked gives you the new boolean.

Example: a reusable text field

import { useState } from 'react';

function NameField({ value, onValueChange }) {
  return (
    <label>
      Display name
      <input value={value}
        onChange={event => onValueChange(event.target.value)} />
    </label>
  );
}

function ProfileEditor() {
  const [name, setName] = useState('');
  return (
    <>
      <NameField value={name} onValueChange={setName} />
      <p>{name.length} characters</p>
    </>
  );
}

The editor owns name, so it can show a character count from the same value it passes to the input. NameField doesn't keep a second copy to synchronize. It can still own unrelated state, such as whether a help tooltip is open.

When to use it and what can go wrong

Controlled fields are useful for live previews, validation messages, and forms where changing one field affects another. If you only need the data when the user submits, uncontrolled fields may need less code. If typing triggers something expensive, such as a suggestions request, update the field's state immediately and debounce the request rather than the state update.

Passing value without a handler that updates it makes an input appear stuck: React keeps restoring the supplied value. If that's intentional, mark the input readOnly. Keep the mode consistent for the lifetime of the same input. For example, use value={name ?? ''} for text loaded asynchronously so the input is controlled from its first render.

In an interview

A common exercise is to build a field that a parent can reset. Explain where the current value lives and follow both update paths: typing notifies the parent, and Reset changes the parent's state directly. If asked why changing defaultValue doesn't do the same thing, point out that it sets the starting value rather than replacing what the user has typed.