compound-pattern

Build coordinated React UI components sharing state via Context and static subcomponents.

235|25|Updated Mar 24, 2026
One-click install
npx skills add https://github.com/PatternsDev/skills --skill compound-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compound-pattern
Source: https://github.com/PatternsDev/skills/tree/main/react/compound-pattern
Command: npx skills add https://github.com/PatternsDev/skills --skill compound-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Build UI components that coordinate behavior and share state without deep prop drilling, enabling cleaner and more maintainable interfaces such as tabs, menus, and dropdowns.

Core Features & Use Cases

  • Use React Context API to share state between a parent component and its children
  • Attach child components as static properties on the parent (e.g., FlyOut.Toggle, FlyOut.List, FlyOut.Item)
  • Memoize context values to avoid unnecessary re-renders in complex layouts
  • Support both explicit subcomponents and React.Children-based composition for flexible APIs

Quick Start

Create a FlyOut component with nested subcomponents (Toggle, List, Item) to coordinate UI state across related elements

Frequently Asked Questions about compound-pattern

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

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

To share state between nested React components without prop drilling, use the compound pattern with React Context. This approach allows parent and child components to coordinate behavior and access shared state implicitly across boundaries.

What is the best way to build coordinated UI components like dropdowns and tabs in React?

The best way to build coordinated UI components like dropdowns and tabs in React is the compound pattern. It uses React Context and static subcomponents to ensure predictable rendering and easy composition across related UI elements.

How do I create a compound component with static subcomponents in React?

Create a compound component by attaching child components as static properties on the parent, such as FlyOut.Toggle, FlyOut.List, and FlyOut.Item. Combine this with React Context to manage shared state and coordinate behavior across the nested elements.

How do I prevent unnecessary re-renders when using React Context for UI state management?

To prevent unnecessary re-renders when using React Context for UI state management, memoize the context values. This optimization ensures predictable rendering performance in complex layouts where parent and child components share implicit state.

Can I use React.Children-based composition instead of explicit subcomponents for UI patterns?

Yes, you can use React.Children-based composition instead of explicit subcomponents for UI patterns. The compound pattern supports both composition methods to provide flexible APIs for building coordinated UI components.