Course contentsShow
← React
Lesson 1144 of 2,39629. Composition: SlotsFree lesson

JSX Props vs Render Props

Compare passing pre-rendered JSX props versus render functions: when static content suffices versus when dynamic generation is needed.

JSX Props vs Render Props

You'll learn when to pass pre-built JSX versus functions that generate JSX dynamically.

The Core Difference

When building flexible components, you have two main approaches for customizable content:

  1. JSX Props: Pass pre-rendered JSX elements as props (e.g., <Card header={<Header />} />)
  2. Render Props: Pass functions that return JSX when called (e.g., <Card header={() => <Header />} />)

The key question: Does your content need to be static or dynamic?

When JSX Props Suffice

Use JSX props when the content is already decided and doesn't need information from the receiving component:

<Layout 
  sidebar={<UserMenu />}
  main={<Dashboard />}
/>

The Layout component simply places these elements—it doesn't need to customize them or pass them data.

When Render Props Are Needed

Use render props when the content depends on internal state or data from the receiving component:

<DataTable 
  row={(item) => <TableRow data={item} />}
/>

Here, DataTable has the item data and needs to pass it to each row. A pre-rendered JSX element couldn't access that data—only a function can receive it as an argument.

The Mental Model

Think of JSX props like pre-made signs you hand to a component: "Put this here." Render props are like instructions: "When you're ready, call this function and I'll create what you need based on what you tell me."

Key Takeaway: Use JSX props for static, pre-built content; use render props when content needs dynamic data or state from the receiving component.