Course contentsShow
← React
Lesson 689 of 2,39618. When NOT to Use useEffectFree lesson

Controlled vs Uncontrolled: Let Parent Own State

How lifting state up eliminates the need for prop-syncing effects in child components.

Controlled vs Uncontrolled: Let Parent Own State

What you'll learn: How lifting state up to the parent component eliminates the need for prop-syncing effects in child components.


The Core Problem

You've learned that syncing props into local state with useEffect creates complexity and bugs. But there's a deeper question: why does the child component own state at all?

When a child component maintains local state that mirrors or derives from props, you're fighting React's natural data flow. The parent sends down props, the child copies them into state, then you need effects to keep them in sync—it's architectural friction.

The Solution: Controlled Components

A controlled component doesn't own its state—the parent does. The child receives the current value as a prop and calls a parent-provided callback to request changes. No local state, no syncing effects, no problems.

Think of it like a TV remote: the TV (child) doesn't remember what channel it's on independently. The cable box (parent) tracks the channel, and the remote just sends "change channel" commands up.

Uncontrolled (child owns state):

// Child fights to sync with parent
function Child({ initialValue }) {
  const [value, setValue] = useState(initialValue);
  // Need effect to sync when initialValue changes... messy!
}

Controlled (parent owns state):

// Child just displays and reports changes
function Child({ value, onChange }) {
  // No local state! Just use what parent gives
  return <input value={value} onChange={onChange} />;
}

The parent holds the state, passes current value down, and receives change events back up. One source of truth, no synchronization needed.

When to Use This Pattern

If the parent cares about the value, lift it up. The child becomes simpler—pure presentation and interaction logic. Save uncontrolled components for truly independent widgets.

Key Takeaway: Making components controlled by lifting state to the parent eliminates prop-syncing effects entirely—the parent is already the source of truth.