component-patterns

Design type-safe React component APIs using compound components, render props, and hooks.

Updated Nov 5, 2025
One-click install
npx skills add https://github.com/wlfmnstr/agentic-knowledge-base --skill component-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: component-patterns
Source: https://github.com/wlfmnstr/agentic-knowledge-base/tree/main/.claude/skills/component-patterns
Command: npx skills add https://github.com/wlfmnstr/agentic-knowledge-base --skill component-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill provides proven React component architecture and composition patterns, helping developers build scalable, maintainable, and accessible UIs. It reduces common pitfalls like prop drilling and ensures type-safe component interactions, accelerating development and reducing bugs.

Core Features & Use Cases

  • Robust Component APIs: Design clear, type-safe props interfaces and extend HTML elements for flexible components.
  • Advanced Composition: Master patterns like Compound Components and Render Props for complex UI logic and state sharing.
  • Use Case: Refactor a large, monolithic React component into a set of smaller, reusable compound components to improve maintainability and allow for more flexible usage across your application, saving development time.

Quick Start

Explain the Compound Components pattern in React and provide a simple example for a Tabs component, including how to manage shared state with React Context.

Frequently Asked Questions about component-patterns

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

FAQPage Schema
How do I structure React components to avoid prop drilling?

Compound Components and Context patterns reduce prop drilling by allowing child components to access shared state without passing props through intermediate layers. These patterns organize related components into cohesive units, simplifying data flow and improving maintainability in TypeScript-based React projects.

What's the best way to design type-safe React component props?

Use TypeScript generics and discriminated unions to create props interfaces that enforce type safety at compile time. This approach extends HTML element props flexibly, catches errors early, and enables IDE autocomplete, reducing bugs in component libraries.

How do I refactor a large React component into reusable pieces?

Break monolithic components into smaller, composable units using Compound Components, Render Props, or custom hooks. This modular approach improves maintainability, enables flexible composition across your application, and accelerates feature development.

Can I use Compound Components with TypeScript for better type safety?

Yes. Compound Components work seamlessly with TypeScript generics and discriminated unions to enforce type-safe interactions between parent and child components, ensuring correct usage patterns and reducing runtime errors in React applications.

What patterns help make React components more accessible and performant?

Memoization, generic components, and accessibility patterns built on semantic HTML and ARIA attributes optimize rendering and ensure screen reader compatibility. These patterns, combined with context and hooks, deliver performant, accessible component libraries.

How do Render Props and custom hooks compare for sharing component logic?

Both patterns share logic across components, but custom hooks offer cleaner syntax and better composability in modern React. Render Props remain valuable for complex conditional rendering. TypeScript generics make both approaches type-safe and maintainable.

Related Skills