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

The Dot Notation Pattern

Attaching child components to the parent: Accordion.Item, Accordion.Trigger, Accordion.Content.

The Dot Notation Pattern

You'll learn how to attach child components directly to the parent component for a cleaner, more discoverable API.

When building compound components like <Accordion>, you could export everything separately:

import { Accordion, AccordionItem, AccordionTrigger, AccordionContent } from './Accordion'

But there's a more elegant approach: the dot notation pattern. Instead of separate named exports, you attach child components as properties of the parent component itself:

<Accordion>
  <Accordion.Item>
    <Accordion.Trigger>Click me</Accordion.Trigger>
    <Accordion.Content>Hidden content</Accordion.Content>
  </Accordion.Item>
</Accordion>

This works because in JavaScript, functions are objects—you can attach properties to them. Here's the implementation pattern:

function Accordion({ children }) {
  // Parent component logic
  return <div className="accordion">{children}</div>
}

function AccordionItem({ children }) {
  return <div className="accordion-item">{children}</div>
}

function AccordionTrigger({ children }) {
  return <button className="accordion-trigger">{children}</button>
}

function AccordionContent({ children }) {
  return <div className="accordion-content">{children}</div>
}

// Attach children to parent
Accordion.Item = AccordionItem
Accordion.Trigger = AccordionTrigger
Accordion.Content = AccordionContent

export default Accordion

Think of it like a toolkit: instead of carrying separate tools, everything is organized in one case. You import Accordion once, and all related pieces come with it.

The benefits are immediate: autocomplete works beautifully, the relationship between components is crystal clear, and you avoid naming collisions (no confusion between AccordionItem and some other Item component).

Key Takeaway: The dot notation pattern attaches child components as properties of the parent (e.g., Accordion.Item = AccordionItem), creating a namespaced, discoverable API that makes compound component relationships explicit.