來源:Vercel
💻

React 元件組合設計

💻跨平台開發與設計

利用複合元件、狀態提升與內部組合,改善 React 元件 API 和可維護性。

收錄依據與使用條件

尚未進行任務實測
來源與依據
Vercel 維護的技能目錄,依原始文件整理用途。查看本次收錄版本
來源文件宣告的平台
來源未明列;尚待逐平台確認。來源說明
適合的任務
重構充滿 boolean props 的元件,建立可重用元件庫。
使用前確認
可讀取的 React 專案與隨附規則;未要求外部服務。 React 19 API 章節僅適用 React 19 以上;舊版必須略過該章節。

資料觀察:2026-10-01 · 中文介紹整理:2026-10-01 · 整個來源專案有 31,774 顆 GitHub stars(非此 skill 的評分或使用人數)

中文介紹依據的原始版本

安裝教學

選擇你使用的 AI coding agent,複製指令到終端機執行

尚未確認此 skill 在此平台的相容性。以下若有指令,僅為通用安裝範本。

安裝指令(需要 Node.js)
npx skills add vercel-labs/agent-skills --skill vercel-composition-patterns -g -a claude-code
手動安裝(不使用 npx)
clone 後複製到 skills 目錄
(
  skill_checkout=$(mktemp -d) &&
  git clone --depth 1 https://github.com/vercel-labs/agent-skills.git "$skill_checkout" &&
  mkdir -p ~/.claude/skills/composition-patterns &&
  cp -R "$skill_checkout/skills/composition-patterns/." ~/.claude/skills/composition-patterns
)

安裝會取得來源的當前版本,可能與本站收錄版本不同。請先閱讀原始文件,確認執行權限與依賴需求。

使用教學

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

來源與授權資訊
Source: https://github.com/vercel-labs/agent-skills/tree/063bee94c3f4df8453406c830b0a7df0f2860278/skills/composition-patterns
Commit: 063bee94c3f4df8453406c830b0a7df0f2860278
Declared license: MIT
Mirror decision: recognized-open-license