Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
itallstartedwithaidea avatar

Composition Patterns

  • 56 installs
  • 31 repo stars
  • Updated April 12, 2026
  • itallstartedwithaidea/agent-skills

Install this when your agent keeps adding boolean props to React components and you want compound-component APIs that stay maintainable as UI grows.

About

Composition Patterns is an agent skill that teaches flexible, maintainable React UI by using compound components, lifting shared state, composing internally, and delegating render slots instead of multiplying boolean flags. Solo and indie builders shipping SaaS or browser extensions with Claude Code, Cursor, or Codex hit a wall when one component accrues dozens of toggles—each boolean doubles effective state space and makes every change a surgery on internals. The skill frames the anti-pattern explicitly and walks agents through four complementary techniques so consumers assemble UI from smaller pieces while shared behavior stays in the right layer. Use it during frontend implementation whenever an agent proposes another `showX` or `enableY` prop, or when a design needs headers, footers, loading states, and variants without forking the base component. It is editorial guidance and procedural knowledge, not a CLI or MCP server; confidence is high for React codebases and lower if you are not on React.

  • Replaces boolean prop explosions (showHeader, isCompact, etc.) with structural composition
  • Covers four patterns: compound components, state lifting, internal composition, render delegation
  • Targets maintainable, consumer-assembled component families instead of monolithic widgets
  • Aimed at agents that default to prop-heavy single components
  • Part of Agent Skills by googleadsagent.ai for React maintainability

Composition Patterns by the numbers

  • 56 all-time installs (skills.sh)
  • +3 installs in the week ending Aug 2, 2026 (Skillselion tracking)
  • Ranked #1,248 of 2,245 Frontend Development skills by installs in the Skillselion catalog
  • Security screen: LOW risk (skills.sh audit)
  • Data as of Aug 4, 2026 (Skillselion catalog sync)
npx skills add https://github.com/itallstartedwithaidea/agent-skills --skill composition-patterns

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs56
repo stars31
Security audit3 / 3 scanners passed
Last updatedApril 12, 2026
Repositoryitallstartedwithaidea/agent-skills

What it does

Install this when your agent keeps adding boolean props to React components and you want compound-component APIs that stay maintainable as UI grows.

Files

SKILL.mdMarkdownGitHub ↗

Composition Patterns

Part of Agent Skills™ by googleadsagent.ai™

Description

Composition Patterns teaches agents to build flexible, maintainable React components using compound components, state lifting, internal composition, and the elimination of boolean prop proliferation. These patterns replace rigid, prop-heavy APIs with composable interfaces that scale gracefully as requirements evolve.

The most common agent mistake in React is building monolithic components with dozens of boolean props: showHeader, showFooter, isCompact, isLoading, hasSearch, enableDarkMode. Each boolean doubles the component's state space, creating an exponential testing surface and making the component impossible to extend without modifying its internals. Composition patterns replace these booleans with structural composition, where the consumer assembles the component from smaller pieces.

This skill addresses four complementary patterns: compound components for related UI families, state lifting for shared cross-component state, internal composition for encapsulated sub-rendering, and render delegation for maximum consumer flexibility. Applied together, these patterns produce components that are simple to use, powerful to customize, and trivial to test.

Use When

  • A component has more than 3 boolean configuration props
  • Related components need to share implicit state (tabs, accordions, selects)
  • The consumer needs to control layout or ordering of sub-elements
  • A component needs to support use cases not anticipated at design time
  • Refactoring a "god component" into composable pieces
  • Building a component library or design system

How It Works

graph TD
    A[Component Design Request] --> B{Pattern Selection}
    B --> C[Compound: Related UI Family]
    B --> D[State Lifting: Shared State]
    B --> E[Internal Composition: Sub-render]
    B --> F[Render Delegation: Consumer Control]
    C --> G[Parent provides context]
    G --> H[Children consume context]
    D --> I[State lives in nearest common ancestor]
    E --> J[Component composes internally]
    F --> K[Consumer passes render function]

The agent selects the appropriate pattern based on the relationship between components, the degree of consumer control needed, and the complexity of shared state.

Implementation

Compound Components

const TabsContext = createContext<TabsState | null>(null);

function Tabs({ defaultValue, children }: TabsProps) {
  const [active, setActive] = useState(defaultValue);
  return (
    <TabsContext.Provider value={{ active, setActive }}>
      <div role="tablist">{children}</div>
    </TabsContext.Provider>
  );
}

function Tab({ value, children }: TabProps) {
  const { active, setActive } = useContext(TabsContext)!;
  return (
    <button
      role="tab"
      aria-selected={active === value}
      onClick={() => setActive(value)}
    >
      {children}
    </button>
  );
}

function TabPanel({ value, children }: TabPanelProps) {
  const { active } = useContext(TabsContext)!;
  if (active !== value) return null;
  return <div role="tabpanel">{children}</div>;
}

Tabs.Tab = Tab;
Tabs.Panel = TabPanel;

// Usage: consumer controls structure
<Tabs defaultValue="a">
  <Tabs.Tab value="a">Tab A</Tabs.Tab>
  <Tabs.Tab value="b">Tab B</Tabs.Tab>
  <Tabs.Panel value="a">Content A</Tabs.Panel>
  <Tabs.Panel value="b">Content B</Tabs.Panel>
</Tabs>

Eliminating Boolean Props

// BAD: Boolean prop explosion
<Card
  showHeader={true}
  showFooter={false}
  isCompact={true}
  hasAvatar={true}
  showActions={true}
/>

// GOOD: Compositional API
<Card compact>
  <Card.Header>
    <Avatar src={user.avatar} />
    <Card.Title>{user.name}</Card.Title>
  </Card.Header>
  <Card.Body>{content}</Card.Body>
  <Card.Actions>
    <Button>Edit</Button>
    <Button>Delete</Button>
  </Card.Actions>
</Card>

Best Practices

  • Use compound components when sub-elements share implicit state
  • Expose composable APIs instead of adding boolean flags for new features
  • Keep context providers narrow—one context per concern, not one mega-context
  • Provide sensible defaults so simple use cases remain simple
  • Document the compositional API with usage examples, not just prop tables
  • Use TypeScript discriminated unions instead of boolean prop combinations

Platform Compatibility

PlatformSupportNotes
CursorFullComponent generation + refactoring
VS CodeFullTypeScript-aware refactoring
WindsurfFullReact pattern recognition
Claude CodeFullComponent design guidance
ClineFullPattern-based generation
aiderPartialLimited compositional awareness

Related Skills

  • React Best Practices
  • View Transitions
  • Web Design Guidelines
  • Edge Rendering

Keywords

composition compound-components react-patterns state-lifting boolean-props render-delegation design-system composable-api

---

© 2026 googleadsagent.ai™ | Agent Skills™ | MIT License

Related skills

FAQ

Is Composition Patterns safe to install?

skills.sh reports 3 of 3 security scanners passed. Review the Security Audits panel on this page before installing in production.

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.