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

Performance Considerations

Understanding re-render implications when passing inline function children and when to memoize.

Performance Considerations

What you'll learn: How passing inline functions as children or render props affects React's re-rendering behavior and when memoization helps.

The Re-Render Problem with Inline Functions

When you pass an inline function as a child or render prop, you create a new function instance on every render. This matters because React uses referential equality checks to decide if props have changed.

// Parent re-renders → new function → child sees "different" prop
<DataProvider>
  {(data) => <ExpensiveChild data={data} />}
</DataProvider>

Every time the parent re-renders, that arrow function is recreated. If ExpensiveChild is wrapped in React.memo(), it won't prevent re-renders because the function prop is technically "different" each time.

When to Memoize

Extract and memoize the render function if the child component is expensive to render:

const renderChild = useCallback(
  (data) => <ExpensiveChild data={data} />,
  [] // Recreate only if dependencies change
);

return <DataProvider>{renderChild}</DataProvider>;

Now renderChild maintains the same identity across renders, allowing React.memo to work properly.

When NOT to Worry

If your child component is lightweight or doesn't use React.memo, inline functions are fine. Premature optimization adds complexity without benefit. The performance cost of creating functions is negligible compared to actual DOM updates.

Analogy: Changing a recipe card (function reference) is cheap; cooking the meal (rendering DOM) is expensive. Only worry about the card when the meal itself is costly.

Key Takeaway: Inline render props create new function references on every render, potentially bypassing React.memo. Use useCallback only when the child is expensive and memoized—otherwise, keep it simple.