vercel-composition-patterns

Structure React components with composition patterns to avoid boolean props.

Updated Oct 7, 2024
One-click install
npx skills add https://github.com/yono92/KeyWork --skill vercel-composition-patterns-yono92
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vercel-composition-patterns
Source: https://github.com/yono92/KeyWork/tree/main/.agents/skills/vercel-composition-patterns
Command: npx skills add https://github.com/yono92/KeyWork --skill vercel-composition-patterns-yono92

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill addresses the complexity of managing React component states and props, offering patterns to create more flexible, readable, and maintainable codebases.

Core Features & Use Cases

  • Avoids Boolean Prop Proliferation: Replaces numerous boolean props with compositional patterns.
  • Compound Components: Structures complex components using shared context for better composition.
  • State Management Decoupling: Separates state logic from UI components for easier swapping of implementations.
  • Use Case: Refactor a large Composer component that has grown unwieldy with many conditional props into smaller, composable variants like ThreadComposer and EditComposer.

Quick Start

Apply the vercel-composition-patterns skill to refactor the Composer component to use explicit variants instead of boolean props.

Frequently Asked Questions about vercel-composition-patterns

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

FAQPage Schema
How do I avoid boolean prop proliferation in React components?

Avoid boolean prop proliferation by replacing conditional props with explicit compositional patterns. Refactor complex components into smaller variants like ThreadComposer and EditComposer to achieve more readable and maintainable codebases.

What is the best way to structure complex React component architecture?

Structure complex React component architecture using compound components with shared context. This pattern decouples state management from UI components, making it easier to swap implementations and scale.

How do I decouple state management from UI components in React?

Decouple state management from UI components by utilizing compound components with shared context. This separation allows easier swapping of state logic implementations and enhances overall flexibility.

Can I use compound components with React 19 API changes?

Yes, compound components with shared context are compatible with React 19 API changes. The approach addresses complex component architectures, reusable component libraries, and flexible API design.

Why does my large React component have too many conditional props?

Large React components accumulate conditional props when relying on boolean flags for variations. Apply composition patterns to refactor unwieldy components into smaller, composable variants for better maintainability.

When do I need composition patterns for React component libraries?

Use composition patterns for React component libraries when building scalable and maintainable architectures. This is needed when designing flexible APIs and decoupling state management from UI components.