The Parent + Children Relationship
What you'll learn: How a parent component acts as the coordinator while multiple specialized child components handle specific parts of the interface.
In compound components, you have a special relationship where a parent component manages the overall state and behavior, while child components are specialized pieces that render specific parts of the UI. The parent doesn't directly render everything—instead, it orchestrates what the children do by sharing context, state, or behavior with them.
Think of it like a restaurant: the parent is the restaurant manager who coordinates reservations, seating arrangements, and overall flow. The children are specialized staff—the host, server, and chef. Each has a specific job, but they all work under the manager's coordination to create a cohesive dining experience.
How It Works
The parent component:
- Holds shared state (like
isOpenfor a dropdown orselectedTabfor tabs) - Provides context or props to coordinate children
- Doesn't dictate exactly what children render—just gives them tools
The child components:
- Are purpose-built for specific UI pieces (like
<Tabs.Tab>or<Select.Option>) - Receive coordination data from the parent (often through context)
- Handle their own specific rendering logic
This relationship creates flexibility: users can arrange children in any order, include only the pieces they need, or even skip some entirely. The parent ensures everything still works together cohesively, even when the structure varies.
Key Takeaway: In compound components, the parent acts as a coordinator providing shared state and behavior, while specialized children components handle specific rendering concerns—creating a flexible yet cohesive API.