What is the difference between controlled and uncontrolled components?

Learn how React manages form inputs using controlled and uncontrolled patterns for better data handling.

intermediateForms and inputsreact formscontrolled inputuncontrolled inputuseRef
Published: 10/26/2025
Updated: 10/26/2025

A controlled component is driven by React state, while an uncontrolled component manages its own state via the DOM.


⚙️ Controlled Example

function Form() {
  const [value, setValue] = useState('');
  return <input value={value} onChange={(e) => setValue(e.target.value)} />;
}

âś… State is the single source of truth.

⚡ Uncontrolled Example

function Form() {
  const inputRef = useRef();
  const handleSubmit = () => alert(inputRef.current.value);
  return <input ref={inputRef} />;
}

âś… Uses the DOM directly (via refs).


Stay Updated

Get the latest frontend challenges, interview questions and tutorials delivered to your inbox.