Course contentsShow
← React
Lesson 281 of 2,3968. Props PatternsFree lesson

Performance Considerations with Render Props

Why inline render functions can cause unnecessary re-renders and when this matters in practice.

Performance Considerations with Render Props

You'll learn: Why passing inline functions to render props can trigger unnecessary re-renders and when this actually matters.

The Inline Function Problem

When you pass an inline arrow function as a render prop, React sees a brand new function every time the parent component re-renders:

function App() {
  return (
    <DataProvider render={(data) => <Display data={data} />} />
  );
}

Every render of App creates a new arrow function. If DataProvider passes this function to a child that uses React.memo or similar optimization, the child thinks its props changed—even when the actual data hasn't.

Think of it like this: Imagine asking someone "Is this the same instruction?" If you rewrite the instruction word-for-word on fresh paper each time, they'll say "No, new paper!" even though the words are identical. That's what happens with inline functions—new reference, triggers re-render.

When It Actually Matters

Honestly? Often it doesn't. React is fast. For most applications, this micro-optimization is premature. Worry about this when:

  • The rendered component tree is expensive to render
  • The render prop component re-renders frequently
  • Profiling shows actual performance issues

The Fix (When Needed)

Extract the function so it has a stable reference:

function App() {
  const renderDisplay = (data) => <Display data={data} />;
  
  return <DataProvider render={renderDisplay} />;
}

But wait—this still creates a new function! For true stability, you'd need useCallback (which you haven't learned yet).

Key Takeaway: Inline render prop functions can cause unnecessary re-renders, but measure first—premature optimization wastes time on problems you don't have.