MyInternships.in

State & Events

React Uncontrolled Components

An uncontrolled input keeps its own value in the DOM, exactly like a plain HTML form. You read the value when you need it — usually on submit — through a ref, and set an initial value with defaultValue rather than value.


What is Uncontrolled Components in React?

An uncontrolled input keeps its own value in the DOM, exactly like a plain HTML form. You read the value when you need it — usually on submit — through a ref, and set an initial value with defaultValue rather than value.

Why Uncontrolled Components matters

For a simple form that only matters at submit time, uncontrolled inputs avoid a re-render per keystroke and less code. File inputs are always uncontrolled because their value cannot be set programmatically.

Uncontrolled Components example

Reading values on submit
JSX
function QuickApply() {
  const nameRef = useRef(null);

  function handleSubmit(e) {
    e.preventDefault();
    console.log(nameRef.current.value);
  }

  return (
    <form onSubmit={handleSubmit}>
      <input ref={nameRef} defaultValue="" />
      <input type="file" name="resume" />   {/* always uncontrolled */}
      <button>Submit</button>
    </form>
  );
}

How this works

The DOM node holds the text; React never re-renders while the user types. On submit you read current.value once.

Controlled vs uncontrolled

ControlledUncontrolled
Source of truthReact statethe DOM node
Initial value propvaluedefaultValue / defaultChecked
Live validationeasyawkward
Renders per keystrokeonenone
Best forvalidation, dependent fields, formattingsimple submit-only forms, file inputs

Common mistakes with Uncontrolled Components

  • Using value instead of defaultValue on an uncontrolled input, which freezes it.
  • Switching a field between controlled and uncontrolled during its lifetime.

React Uncontrolled Components— Interview Questions & FAQs

When should I use uncontrolled inputs?+

When you only need the value at submit time and want no per-keystroke re-render — and for file inputs, which are uncontrolled by definition. Anything needing live validation or dependent fields should be controlled.

Related React Topics

Keep learning with these closely related lessons.

Ready to use your React skills?

Find verified React internships and fresher developer jobs across India.

Browse React Internships