compound-pattern

Coordinate React subcomponents through shared parent state via Context API.

Updated Apr 28, 2026
One-click install
npx skills add https://github.com/PMKhai/claude-config --skill compound-pattern-pmkhai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compound-pattern
Source: https://github.com/PMKhai/claude-config/tree/main/skills/compound-pattern
Command: npx skills add https://github.com/PMKhai/claude-config --skill compound-pattern-pmkhai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Coordinate related UI components through a shared state to avoid prop drilling in complex component trees.

Core Features & Use Cases

  • Centralizes state for related sub-components (Toggle, List, Item) within a parent component.
  • Enables clean public APIs by attaching subcomponents as static properties (e.g., FlyOut.Toggle, FlyOut.List, FlyOut.Item).
  • Supports flexible rendering via Context API or prop-based cloning with memoized values for performance.
  • Use cases include dropdown menus, tabs, and menus with coordinated behavior without explicit prop passing.

Quick Start

Create a FlyOut compound component with Toggle and List subcomponents to demonstrate shared state across children.

Frequently Asked Questions about compound-pattern

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

FAQPage Schema
How do I avoid prop drilling when coordinating state across related React UI components?

To avoid prop drilling in React UI components, you can centralize shared state within a parent component and distribute it to subcomponents via the Context API. This allows nested children to access state without explicit prop passing.

What is the best way to structure a dropdown menu in React without passing props to every child?

The best way to structure a dropdown menu in React without passing props to every child is using a compound component pattern. This attaches subcomponents like Toggle and List as static properties of the parent, sharing state implicitly through context.

How does the Context API work with compound components for shared state management?

The Context API works with compound components by providing a centralized state from the parent component to all subcomponents. This contextual sharing mechanism bypasses prop drilling, allowing components like Toggle and Item to coordinate behavior directly.

Can I use prop cloning instead of the Context API for React component architecture?

Yes, you can use prop cloning instead of the Context API for React component architecture. The compound component pattern supports both flexible rendering via Context API and prop-based cloning, utilizing memoized values to maintain rendering performance.

When should I use the compound pattern for my React component architecture?

You should use the compound pattern for React component architecture when building coordinated UI elements like dropdowns, tabs, and menus. It is ideal when a parent component needs to own state while subcomponents require shared access without explicit prop passing.

Does memoizing state values improve performance in compound React components?

Yes, memoizing state values improves performance in compound React components. By applying state memoization to the shared values passed through the Context API or prop cloning, you prevent unnecessary re-renders of coordinated subcomponents like Toggle, List, and Item.