The Callback Reference Problem
What you'll learn: How inline arrow functions in props create new references on every render and when that actually becomes a performance issue.
The Core Problem
Every time a component renders, any inline arrow function you write creates a brand new function object, even if the code inside is identical. JavaScript sees these as different references.
function Parent() {
return <Child onClick={() => console.log('clicked')} />;
}
Every render of Parent creates a new onClick function. If Child is wrapped in React.memo, it will re-render anyway because the prop reference changed.
Why This Matters (and When It Doesn't)
It usually doesn't matter. Creating functions is cheap. The problem only appears when:
- The child component is expensive to render AND wrapped in
React.memo - The callback is used as a dependency in
useEffectoruseMemoin the child - You're passing callbacks to hundreds of list items
The Analogy
Imagine giving someone directions. Even if you say the exact same words each time ("turn left at Main Street"), you're creating a new instance of those instructions. React sees each repetition as a different thing, even though the content is identical.
When to Actually Care
If Child renders fast, don't optimize. If you see performance issues in the Profiler and trace them to callback prop changes, then reach for useCallback. Premature optimization adds complexity without benefit.
Key Takeaway: Inline arrow functions create new references every render, but this only matters for memoized components or dependency arrays—profile first, optimize second.