When Components Re-render: The Trigger Rules
What you'll learn: The specific conditions that cause a React component to re-render (and why "props changed" isn't one of them on its own).
The Three Re-render Triggers
Understanding when components re-render is critical for building performant React apps. There are exactly three triggers that cause a component to re-render:
1. State Changes
When you call a state setter function (like setCount), React schedules a re-render of that component. This is the most common trigger you've already been using.
2. Parent Re-renders
When a parent component re-renders, all of its children re-render by default—even if their props haven't changed. This is React's safe default behavior.
3. Context Value Changes
When a context value updates, all components consuming that context re-render (you'll learn about Context later).
The Props Misconception
Props changing alone does NOT trigger a re-render. This surprises many beginners. Props are simply arguments passed to your component function. React doesn't "watch" props—it re-renders the child because the parent re-rendered (trigger #2), which causes the child function to be called again with new props.
Think of it like a function call: if you call greet("Alice") and then greet("Bob"), the function doesn't "detect" that "Alice" became "Bob"—you simply called it again with different arguments.
Why This Matters
Understanding these triggers helps you reason about:
- Why your component updated unexpectedly
- Why changing props directly doesn't do anything
- How to optimize by preventing unnecessary parent re-renders
Key Takeaway: Components re-render when (1) their own state changes, (2) their parent re-renders, or (3) consumed context changes. Props are simply new values received during the parent's re-render—they're not an independent trigger.