Loading...
Loading...
Composition Patterns teaches agents to build flexible, maintainable React components using compound components, state lifting, internal composition, and the elimination of boolean prop proliferation.
npx skill4agent add itallstartedwithaidea/agent-skills composition-patternsshowHeadershowFooterisCompactisLoadinghasSearchenableDarkModegraph 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]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>// 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>| Platform | Support | Notes |
|---|---|---|
| Cursor | Full | Component generation + refactoring |
| VS Code | Full | TypeScript-aware refactoring |
| Windsurf | Full | React pattern recognition |
| Claude Code | Full | Component design guidance |
| Cline | Full | Pattern-based generation |
| aider | Partial | Limited compositional awareness |
compositioncompound-componentsreact-patternsstate-liftingboolean-propsrender-delegationdesign-systemcomposable-api