Composition with Multiple Children
What you'll learn: How to design parent components that coordinate multiple distinct child components into a structured layout.
The Coordination Pattern
So far you've nested components one at a time. But real UIs often need a parent component to manage multiple children working together—like a UserProfile that coordinates a ProfileHeader, AboutSection, and ContactInfo all at once.
This is composition with multiple children: building parent components that accept and render several child components in a coordinated layout.
How It Works
The parent component calls multiple child components in its JSX, arranging them into a cohesive structure:
function UserProfile() {
return (
<div className="profile-container">
<ProfileHeader />
<AboutSection />
<ContactInfo />
</div>
);
}
The parent decides:
- Which children to include
- What order they appear in
- How they're wrapped (in a div, a section, etc.)
Each child component handles its own content and structure. The parent just orchestrates the layout.
Why This Matters
Instead of one massive component, you break UIs into coordinated pieces. A Dashboard might compose Sidebar, MainContent, and Footer. A ProductPage might coordinate ImageGallery, ProductDetails, and Reviews.
Each child stays focused. The parent stays clean. Changes to one piece don't affect others.
Key Takeaway: Parent components can coordinate multiple children by calling them in sequence, creating structured layouts where each child focuses on its own responsibility while the parent manages the overall composition.