Skip to content

Controlled vs Uncontrolled Components (Forms)

How to think about form inputs, refs, and when each approach makes sense.

Rajesh DhimanFebruary 08, 20262 min read
On this page

30‑second interview answer

A controlled input stores its value in React state (value + onChange). An uncontrolled input lets the DOM keep the value, and React reads it via a ref when needed. Controlled is more predictable (validation, conditional UI), while uncontrolled can be simpler and faster for basic forms.


Controlled components

Example

function Controlled() {
  const [email, setEmail] = useState('');
 
  return (
    <input
      value={email}
      onChange={(e) => setEmail(e.target.value)}
      placeholder="you@example.com"
    />
  );
}

Pros

  • Single source of truth
  • Easy validation
  • Easy conditional UI (disable submit, show errors)
  • Works well with form libraries

Cons

  • More code
  • Can cause more renders if the form is large (usually fine)

Uncontrolled components

Example

function Uncontrolled() {
  const ref = useRef(null);
 
  function handleSubmit(e) {
    e.preventDefault();
    const value = ref.current.value;
    console.log(value);
  }
 
  return (
    <form onSubmit={handleSubmit}>
      <input ref={ref} defaultValue="" />
      <button>Submit</button>
    </form>
  );
}

Pros

  • Less state management
  • Good when you only need value on submit

Cons

  • Harder to validate continuously
  • Harder to keep UI synced with input value

When to use which (practical rules)

Use controlled when:

  • you need realtime validation
  • you need to conditionally show UI based on input
  • you need to enforce formats (masking)
  • you use React Hook Form in controlled mode

Use uncontrolled when:

  • form is simple
  • you only care on submit
  • you want minimal React state

Interview-ready line:

“Controlled is default for predictability; uncontrolled is fine for simple forms or when using refs intentionally.”


Common traps interviewers ask

1) Mixing value and defaultValue

  • value makes it controlled.
  • defaultValue is for uncontrolled initial value.

Don’t do both.

2) Forgetting onChange with value

You’ll get a read-only input.

3) Performance fear

Most forms are fine controlled. If you have huge forms, use libraries (React Hook Form) that optimize or consider uncontrolled inputs.


Mini Q&A

Q1: Controlled vs uncontrolled?

  • State-driven vs DOM-driven.

Q2: Which is easier to validate?

  • Controlled.

Q3: When is uncontrolled useful?

  • Simple forms, read value on submit, performance-optimized form libraries.

Summary checklist

  • I can define controlled vs uncontrolled.
  • I can code both patterns.
  • I know when each is appropriate.
  • I avoid mixing value and defaultValue.
Companion Book

Looking for structured, offline interview prep?

Free online lessons • Portable Amazon Kindle / Paperback

Frontend Interview Guide (2025 Edition) cover
Recommended for React & Frontend Rounds

Frontend Interview Guide (2025 Edition)

By Rajesh Dhiman

Comprehensive preparation covering React internals, Web Performance, CSS architecture, and system design questions.

View on Amazon ↗Kindle & Paperback
JavaScript Interview Guide cover
Recommended for Core JS Rounds

JavaScript Interview Guide

By Rajesh Dhiman

Deep dive into the Event Loop, microtask draining, closures, prototypal inheritance, and asynchronous execution patterns.

View on Amazon ↗Kindle & Paperback

Note: All lessons on Frontend Interview remain completely free to read online. As an Amazon Associate, we may earn from qualifying purchases.

RD

Written by Rajesh Dhiman

Authored by Rajesh Dhiman and engineered at Eunix Tech. Focused on deep-dive frontend engineering, JavaScript runtime internals, React architecture, and web performance.