Course contentsShow
← React
Lesson 1050 of 2,39627. Composition: Render PropsFree lesson

Performance Consideration: Inline Function Identity

Inline render functions create new references each render, potentially causing child re-renders if not carefully managed.

Performance Consideration: Inline Function Identity

You'll learn: Why passing inline arrow functions as render props can accidentally trigger extra re-renders and how to recognize this issue.

The Core Concept

When you pass an inline function as a render prop, React creates a brand new function on every render. Even though the function does the same thing, it's a different object in memory each time. If the component receiving this render prop checks whether its props have changed (using React.memo or PureComponent), it will see a "new" prop every time and re-render—even when nothing meaningful changed.

Why This Matters

// Every render creates a NEW function
<MouseTracker render={(x, y) => (
  <p>Mouse at {x}, {y}</p>
)} />

Each time the parent re-renders, (x, y) => ... is a fresh function. It's like getting a new phone number that does the same job—technically different, even if functionally identical.

If MouseTracker uses React.memo, it can't tell this function is "the same" as before. It sees a different reference and re-renders unnecessarily.

The Simple Fix

Extract the function outside or use useCallback (when you learn it):

// Same function reference across renders
const renderMouse = (x, y) => <p>Mouse at {x}, {y}</p>;

<MouseTracker render={renderMouse} />

Now renderMouse has a stable identity. Memoized components can recognize "nothing changed" and skip rendering.

Key Takeaway: Inline render prop functions create new identities each render, which can defeat memoization. For performance-critical components, extract or stabilize the function reference.