Course contentsShow
← React
Lesson 1081 of 2,39628. Composition: Compound ComponentsFree lesson

Implicit Communication Without Props

How compound components share state internally without requiring consumers to pass props between them.

Implicit Communication Without Props

What you'll learn: How compound components share state internally so consumers don't have to manually wire props between parent and child.

The Problem with Explicit Props

Normally when components need to share data, you pass props down explicitly:

<Tabs activeTab={activeTab} onChange={setActiveTab}>
  <TabButton id="home" activeTab={activeTab} onChange={setActiveTab}>
    Home
  </TabButton>
  <TabButton id="profile" activeTab={activeTab} onChange={setActiveTab}>
    Profile
  </TabButton>
</Tabs>

Notice how activeTab and onChange get repeated everywhere? That's tedious and error-prone.

Implicit Communication: The Secret Handshake

Compound components use Context (or similar mechanisms) to share state invisibly. The parent component owns the state and makes it available to its children without requiring the consumer to pass it along:

<Tabs defaultTab="home">
  <TabButton id="home">Home</TabButton>
  <TabButton id="profile">Profile</TabButton>
</Tabs>

Behind the scenes, Tabs provides the active tab state, and each TabButton consumes it automatically. The consumer's code stays clean and simple.

The Analogy

Think of a restaurant: the kitchen (parent) and waitstaff (children) communicate through a shared system. Customers (consumers) don't need to tell each waiter what the kitchen knows—they just order from the menu, and the internal communication handles the rest.

Why This Matters

Implicit communication creates a better API. Consumers focus on what they want ("show these tabs"), not how the components coordinate internally. The compound components handle their own state-sharing logic, making the pattern delightful to use.

Key Takeaway: Compound components hide internal state-sharing from consumers, eliminating repetitive prop-passing and creating cleaner, more intuitive APIs.