compound-pattern

Manage shared implicit state across coordinated React subcomponents using Context.

1|Updated Jul 12, 2025
One-click install
npx skills add https://github.com/ubay1/next15-starter --skill compound-pattern-ubay1
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compound-pattern
Source: https://github.com/ubay1/next15-starter/tree/main/.agents/skills/compound-pattern
Command: npx skills add https://github.com/ubay1/next15-starter --skill compound-pattern-ubay1

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The compound component pattern solves the challenge of building multiple related UI parts that must coordinate shared state without forcing consumers to manually wire that state through many props.

Core Features & Use Cases

  • Shared implicit state via React Context: Lets a parent compound component manage state and expose it to its children safely and ergonomically.
  • Static child components on the parent: Provides a discoverable API like Parent.Toggle and Parent.List so consumers import only the parent component.
  • Coordinated interactive widgets: Ideal for dropdowns, tabs, accordions, and menu-like components where subcomponents open/close or act together.

Quick Start

Create a parent compound component that holds the open/closed state in Context and expose subcomponents as static properties (for example Toggle and List) so consumers can compose the UI by nesting children under the parent.

Frequently Asked Questions about compound-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I share implicit state between related React components without prop drilling?

To share implicit state across related React components without prop drilling, use the compound component pattern with React Context. A parent component manages the shared state and exposes it to children automatically, ensuring synchronized behavior in coordinated UI widgets like dropdowns and tabs.

What is the compound component pattern in React and when should I use it?

The compound component pattern in React is a design approach where a parent component manages shared state via Context and exposes static child components like Parent.Toggle and Parent.List. Use it for coordinated interactive widgets such as dropdowns, tabs, accordions, and menus where subcomponents act together.

How do I build a React dropdown menu with a clean component API?

Build a React dropdown menu by creating a parent compound component that holds the open or closed state in Context. Attach subcomponents like Toggle and List as static properties on the parent so consumers can compose the UI by nesting children, avoiding manual state wiring through props.

Why do my React context components re-render unnecessarily and how do I optimize them?

React context components re-render unnecessarily when the context value changes on every render. Optimize them by using memoized context values within the compound component pattern, ensuring that coordinated UI subcomponents only re-render when the shared implicit state actually changes.

Can I use the compound component pattern for React tabs and accordions?

Yes, the compound component pattern is ideal for React tabs and accordions. It manages shared implicit state across related subcomponents using Context, allowing multiple children to react to a single internal state for opening and closing without forcing consumers to manually wire props.

How do I expose static child components on a parent React component?

Expose static child components on a parent React component by assigning them as properties of the parent, such as Parent.Toggle and Parent.List. This provides a discoverable API for the compound component pattern, letting consumers import only the parent while composing coordinated UI subcomponents.