building-compound-components

Design unstyled compound React component APIs with context and render props.

Updated Apr 26, 2026
One-click install
npx skills add https://github.com/awardsapp/tambo-genui --skill building-compound-components-awardsapp
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: building-compound-components
Source: https://github.com/awardsapp/tambo-genui/tree/main/.claude/skills/compound-components
Command: npx skills add https://github.com/awardsapp/tambo-genui --skill building-compound-components-awardsapp

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps you design compound React components that keep behavior isolated from styling so you can build accessible, Radix-style UI primitives without coupling implementation details to presentation.

Core Features & Use Cases

  • Unstyled compound primitives: Create composable React components where consumers control rendering and styling.
  • Context-driven behavior with fail-fast safety: Provide internal state via context and throw a clear error when used without the required provider (e.g., outside Component.Root).
  • Render props for consumer state access: Expose internal state to consumers without exporting hooks, enabling deterministic UI integration patterns.
  • API patterns for polymorphism and collections: Support asChild via Radix Slot, forward refs, use data attributes for state styling, and pre-compute props arrays with useMemo.

Quick Start

Ask your AI to produce an unstyled Component.Root + namespaced consumer components (like Trigger and Content) that use context internally, support asChild, and expose state to consumers via render props.

Frequently Asked Questions about building-compound-components

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

FAQPage Schema
How do I build unstyled compound React components with separated behavior and styling?

You build unstyled compound React components by designing namespaced component APIs that isolate behavior from presentation, using internal context for state distribution and exposing data via render props. This allows consumers to fully control rendering and styling.

What is the best way to expose internal state in headless UI primitives without exporting hooks?

The best way to expose internal state in headless UI primitives is through render props. By pre-computing props arrays with useMemo, you provide deterministic state access to consumers directly within the JSX layer without needing to export internal context hooks.

How does context fail-fast safety work when developing Radix-style React primitives?

Context fail-fast safety in Radix-style React primitives throws a clear error when a consumer component is rendered outside its required provider, such as a Trigger used outside Component.Root. This prevents silent state failures and ensures correct provider nesting.

Can I use asChild and forwardRef patterns together in headless React components?

Yes, you can use asChild and forwardRef patterns together in headless React components. This Skill implements polymorphic rendering via Radix Slot to merge refs and props, ensuring consumer elements receive accurate ref forwarding while maintaining component behavior.

When should I use data-state attributes instead of render props for styling React primitives?

Use data-state attributes for CSS-driven styling when you need to toggle visual states purely through stylesheets, and use render props when consumers require programmatic access to the internal state values for conditional rendering logic within their JSX.

Why do my compound React components trigger context safety errors during collection rendering?

Compound React components trigger context safety errors during collection rendering if items are rendered outside the root provider hierarchy. You must ensure all namespaced consumer components are nested correctly within Component.Root to access the required internal context.