compound-pattern

Implement React compound components sharing state via Context.

Updated May 20, 2026
One-click install
npx skills add https://github.com/Hollowvyn/cognipace-v2 --skill compound-pattern-hollowvyn
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: compound-pattern
Source: https://github.com/Hollowvyn/cognipace-v2/tree/main/.agents/skills/compound-pattern
Command: npx skills add https://github.com/Hollowvyn/cognipace-v2 --skill compound-pattern-hollowvyn

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

The compound component pattern helps you build coordinated UI subcomponents that share implicit state without forcing consumers to manually thread props.

Core Features & Use Cases

  • Shared implicit state via Context: Use React Context so a parent owns the state and children read it cleanly.
  • Ergonomic component API: Expose related children as static properties (for example, Tabs.Tab, Tabs.Panel) so consumers import only the parent.
  • Coordinated behavior for interactive widgets: Great for dropdowns, tabs, accordions, menus, and other multi-part components that must stay in sync.

Quick Start

Use the compound-pattern skill when you are designing a React component like tabs or a dropdown where the toggle and content must coordinate without explicit prop passing.

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 React tabs or dropdown components without prop drilling?

Use compound components to share implicit state via React Context, allowing a parent widget like tabs or a dropdown to own the state while child components read it cleanly without manual prop threading.

What is the compound component pattern in React?

The compound component pattern builds coordinated UI subcomponents that share implicit state, using React Context so related pieces like a dropdown toggle and its content stay synchronized without forcing consumers to pass props explicitly.

How do I structure a React component API so consumers only import the parent?

Attach related child components as static properties on the parent, such as Tabs.Tab and Tabs.Panel, so consumers import only the parent component while retaining ergonomic access to all coordinated subcomponents.

When should I use compound components for interactive UI widgets?

Use compound components for multi-part interactive widgets like tabs, dropdowns, accordions, and menus where parent-owned state must drive multiple children and keep related UI pieces synchronized.

Does the compound component pattern prevent excessive re-renders in React?

The compound component pattern supports optional memoization to prevent excessive re-renders, ensuring that only the relevant child components update when the shared Context state changes.

Do I need React Context to implement compound components?

Yes, React Context is required for the compound component pattern to share internal state among related subcomponents, enabling the parent to own the state and children to access it cleanly.