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

Discovery and Documentation

Making compound component APIs discoverable through autocomplete and clear naming conventions.

Discovery and Documentation

You'll learn how to make compound component APIs easy to discover and use through smart naming conventions and autocomplete-friendly patterns.

The Discoverability Problem

When you build compound components, you're creating a mini-ecosystem of related components. Without clear guidance, developers using your API might not realize which components belong together or how they should be assembled. Good discovery means users can find what they need through IDE autocomplete and intuitive naming—without diving into documentation.

Naming for Autocomplete

The dot notation pattern (Menu.Item, Tabs.Panel) isn't just aesthetic—it's a discovery tool. When a developer types Menu., their IDE instantly shows all related components. This creates a guided exploration experience.

// ✅ Discoverable through autocomplete
<Tabs>
  <Tabs.List>
    <Tabs.Tab>Profile</Tabs.Tab>
    <Tabs.Tab>Settings</Tabs.Tab>
  </Tabs.List>
  <Tabs.Panel>Profile content</Tabs.Panel>
  <Tabs.Panel>Settings content</Tabs.Panel>
</Tabs>

Clear, Descriptive Names

Avoid generic names like Item or Child when exporting directly. Instead, make the relationship obvious: AccordionItem clearly belongs with Accordion. Each component name should communicate both its purpose and its parent relationship.

Documentation Through Type Safety

TypeScript interfaces become living documentation. When you define explicit prop types for each compound component, IDEs show users exactly what's available and required—no docs tab needed.

Key Takeaway: Design compound component APIs for IDE discoverability first—the dot notation pattern, clear naming, and strong types turn your component library into a self-documenting system that guides users naturally.