Render Props

Last updated: 2026-11-02

Render Props Render Props

Render props means passing the JSX you want rendered to a component as a function prop: the component owns the logic and the state, while the caller receives the data as an argument and decides what to render. It decouples logic reuse from UI customization, and it was the most common reuse pattern before hooks arrived. Because the data arrives as a plain argument, one implementation can serve many very different interfaces without knowing anything about any of them.

GroupComponent Patterns
KindPattern

ℹ️ Info The editor transpiles JSX to JavaScript and renders the real UI in a sandbox; components mount automatically — no manual render call needed.

📝 Syntax

function DataProvider({ render }) {
  const data = /* the data produced by the logic */
  return render(data)          // call the render function and hand the data back
}

// usage: <DataProvider render={data => <List items={data} />} />

Returns:No return value; this entry describes an encoding pattern rather than a function.

▶ Example

The example runs out of the box: it auto-renders when expanded, and edits take effect instantly.

Output:

The same Counter logic is rendered into two completely different interfaces, and the two counters accumulate independently without interfering with each other.

💡 Key Points

ℹ️ Info Children can also be a function — <Counter>{count => …}</Counter> — which is the same mechanism as a render prop.
💡 Tip Extracting the logic into a custom hook such as useCounter is usually more concise than render props, and the two can coexist.
⚠️ Warning Nesting render props components deeply produces a pyramid of indentation; since hooks arrived most of those cases have been replaced.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q Are render props and function children the same thing?
A The mechanism is identical: you pass a function as a prop and the component calls it with the data. A function child is just a more compact spelling.
Q Do we still need render props now that hooks exist?
A Hooks are better for most logic reuse, but render props still fit when one piece of logic must render very different interfaces and you want to take over the view completely.
Q Is the render function rebuilt on every render?
A Yes, it is an inline arrow function. A render props component only calls it without a memo shallow comparison, so it usually does not become a performance problem.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏