New to Claude Skills? Learn how to install them →

tech-leads-club on GitHub

React Composition Patterns

Free

Build flexible and maintainable React components.

Get this skill

Free · Opens the source repo

What React Composition Patterns does

React Composition Patterns provides a structured approach to building flexible and maintainable components in React. This skill focuses on avoiding boolean prop proliferation, which can lead to complex and hard-to-manage components. Instead, it advocates for using composition techniques such as compound components and lifting state, which not only simplify the code but also enhance its scalability. By following these patterns, developers can create component libraries that are easier to use and maintain, benefiting both human developers and AI agents alike.

This skill is particularly useful when refactoring existing components that have become unwieldy due to excessive boolean props. It offers guidelines for building reusable component libraries and designing flexible APIs that can adapt to various use cases. The skill also includes insights into the latest changes in React 19, ensuring that developers are up-to-date with the most current practices in component architecture and state management.

Each guideline within this skill is categorized by priority, allowing users to focus on the most impactful areas first. The rules cover essential topics such as avoiding boolean props, structuring complex components with shared context, and decoupling state management from implementation details. For each rule, detailed explanations, incorrect and correct code examples, and additional context are provided to facilitate understanding and implementation.

Overall, React Composition Patterns serves as a comprehensive resource for developers looking to enhance their React component design practices, making their codebases more maintainable and scalable as they grow.

When to use it

Use this skill when refactoring components, building reusable libraries, or designing flexible APIs in React applications.

When not to use it

This skill is not suitable for performance optimization tasks in React or Next.js applications; use react-best-practices for those scenarios instead.

What you can build with it

Refactoring Legacy Components

Use this skill to refactor legacy React components that rely heavily on boolean props, improving their maintainability and readability.

Building a Component Library

When creating a reusable component library, apply these composition patterns to ensure your components are flexible and easy to integrate.

Designing APIs for React Components

Utilize this skill to design APIs for your components that prioritize usability and scalability, making them easier for other developers to work with.

How to install React Composition Patterns

View source

1. Install with the skills CLI

npx skills add tech-leads-club/agent-skills/react-composition-patterns --agent claude-code

2. Or install it manually

Download the skill folder and drop it into ~/.claude/skills/ for all projects, or .claude/skills/ to scope it to one repo. Restart Claude Code so it picks up the new skill.

Anthropic's agentic coding CLI, and the reference implementation of Agent Skills. Drop a skill folder into ~/.claude/skills and Claude Code loads it automatically whenever a task matches the skill's description. Claude Code docs

Inside SKILL.md

Written by tech-leads-club

React Composition Patterns

Composition patterns for building flexible, maintainable React components. Avoid boolean prop proliferation by using compound components, lifting state, and composing internals. These patterns make codebases easier for both humans and AI agents to work with as they scale.

When to Apply

Reference these guidelines when:

  • Refactoring components with many boolean props
  • Building reusable component libraries
  • Designing flexible component APIs
  • Reviewing component architecture
  • Working with compound components or context providers

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Component ArchitectureHIGHarchitecture-
2State ManagementMEDIUMstate-
3Implementation PatternsMEDIUMpatterns-
4React 19 APIsMEDIUMreact19-

Quick Reference

1. Component Architecture (HIGH)

  • architecture-avoid-boolean-props - Don't add boolean props to customize behavior; use composition
  • architecture-compound-components - Structure complex components with shared context

2. State Management (MEDIUM)

  • state-decouple-implementation - Provider is the only place that knows how state is managed
  • state-context-interface - Define generic interface with state, actions, meta for dependency injection
  • state-lift-state - Move state into provider components for sibling access

3. Implementation Patterns (MEDIUM)

  • patterns-explicit-variants - Create explicit variant components instead of boolean modes
  • patterns-children-over-render-props - Use children for composition instead of renderX props

4. React 19 APIs (MEDIUM)

⚠️ React 19+ only. Skip this section if using React 18 or earlier.

  • react19-no-forwardref - Don't use forwardRef; use use() instead of useContext()

How to Use

Read individual rule files for detailed explanations and code examples:

rules/architecture-avoid-boolean-props.md
rules/state-context-interface.md

Each rule file contains:

  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md

Frequently asked questions about React Composition Patterns

Similar skills