Multiple Invocations of Function Children
You'll learn: How parent components can call a function child multiple times to render lists or repeated patterns.
The Core Idea
Until now, you've seen function children called once per render. But there's no rule saying you can only invoke the function once—a parent component can call that function child multiple times in the same render cycle, passing different data each time.
This becomes powerful when you need to render lists or repeated UI patterns. Instead of the parent deciding how each item looks, it calls your function child for every item, letting you define the presentation while the parent handles the iteration logic.
How It Works
The parent component might loop over an array and invoke the function child once per array element, passing that element's data as an argument:
function UserList({ users, children }) {
return (
<ul>
{users.map(user => (
<li key={user.id}>
{children(user)}
</li>
))}
</ul>
);
}
// Usage
<UserList users={[{id: 1, name: 'Alice'}, {id: 2, name: 'Bob'}]}>
{(user) => <span>{user.name}</span>}
</UserList>
Here, children(user) gets called twice—once for Alice, once for Bob. The parent handles the <ul>, <li>, and key logic; you control what goes inside each list item.
Why This Matters
Multiple invocations let you separate iteration logic (how many times to repeat) from presentation logic (what each repetition looks like). The parent owns the data and structure; you own the rendering.
Key Takeaway: Function children can be invoked multiple times per render, enabling parents to handle iteration while you control individual item presentation—perfect for list rendering with flexible UI.