vercel-composition-patterns

Guide React component composition with compound components and explicit variants.

2|Updated Nov 14, 2024
One-click install
npx skills add https://github.com/fkoschi/grind-it --skill vercel-composition-patterns-fkoschi
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: vercel-composition-patterns
Source: https://github.com/fkoschi/grind-it/tree/main/.agents/skills/vercel-composition-patterns
Command: npx skills add https://github.com/fkoschi/grind-it --skill vercel-composition-patterns-fkoschi

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill addresses the complexity of building and maintaining React components, particularly those that grow unwieldy with numerous conditional props or complex state management.

Core Features & Use Cases

  • Component Architecture: Guides on avoiding boolean prop proliferation and using compound components for better structure.
  • State Management: Strategies for decoupling state from UI, defining generic context interfaces, and lifting state into providers.
  • Implementation Patterns: Best practices for creating explicit component variants and preferring children over render props.
  • React 19 APIs: Covers new API changes like use() and direct ref handling.
  • Use Case: Refactoring a large UserProfile component that currently uses many boolean flags (e.g., isEditing, showAvatar, isPrivate) into a more composable structure using compound components and explicit variants.

Quick Start

Apply the vercel-composition-patterns skill to refactor the Composer component in src/components/Composer.tsx to use compound components and avoid boolean prop proliferation.

Frequently Asked Questions about vercel-composition-patterns

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

FAQPage Schema
How do I refactor React components with too many boolean props?

Refactor React components with boolean prop proliferation by applying compound components and explicit variants. This pattern decouples state from UI and structures elements through composition, resulting in clearer and more maintainable code.

What is the best way to manage state in scalable React component architecture?

State management in scalable React component architecture is best handled by decoupling state from UI, defining generic context interfaces, and lifting state into context providers. This strategy improves code clarity and reusability.

How do compound components improve React state management?

Compound components improve React state management by structuring elements through composition rather than conditional logic. This approach prevents boolean prop proliferation, lifts state into providers, and uses explicit variants to enhance code clarity.

Can I use the React 19 use() API for component composition?

Yes, the React 19 use() API is supported for component composition. This Skill provides guidelines covering new API changes like use() and direct ref handling to improve implementation strategies and maintainability.

When should I prefer children over render props in React component architecture?

Prefer children over render props in React component architecture when building compound components to improve code clarity. This implementation pattern avoids complex conditional logic and promotes explicit component variants.

Does this approach work for refactoring a large UserProfile component?

Yes, this approach works for refactoring a large UserProfile component. It guides transforming structures with many boolean flags like isEditing into a composable structure using compound components and explicit variants.