Course contentsShow
← React
Lesson 236 of 2,3967. Props FundamentalsFree lesson

Callback Identity and Re-renders

How creating new function instances on every render can cause child components to re-render unnecessarily.

Callback Identity and Re-renders

What you'll learn: How creating new function instances on every render can cause child components to re-render unnecessarily.

The Core Problem

Remember how we said components re-execute on every render? That means every function you define inside a component gets created fresh each time. Even if two functions do the exact same thing, React sees them as different objects if they're created separately.

This matters when you pass callbacks as props, because React checks if props have changed to decide whether a child component needs to re-render. If you pass a new function instance every time, React thinks the prop changed—even if the function does the same thing.

The Pattern That Causes Extra Renders

function Parent() {
  return <Child onClick={() => console.log('clicked')} />
}

Every time Parent renders, that arrow function is recreated. To React, it's a "new" onClick prop each time, so Child re-renders—even if nothing else changed.

Why This Happens

Functions are reference values in JavaScript. Two functions with identical code are still different objects:

const func1 = () => console.log('hi');
const func2 = () => console.log('hi');
console.log(func1 === func2); // false — different objects!

Each render creates a new function reference, so React sees a different prop value.

The Impact

For most apps, this isn't a performance problem—renders are fast. But if you're rendering large lists or expensive components, these unnecessary re-renders add up. Understanding callback identity helps you optimize later.

Key Takeaway: Creating inline functions on every render creates new function instances, causing React to treat them as "changed" props and potentially triggering unnecessary child re-renders.