Skills 週期表
← 回到週期表

ELEMENT 022 · 開發與設計

React 元件組合設計

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

來源
Vercel
授權
MIT
上游路徑
skills/composition-patterns
同步
1a2c79d

開始之前

適合的任務
重構充滿 boolean props 的元件,建立可重用元件庫。
使用前確認
可讀取的 React 專案與隨附規則;未要求外部服務。 React 19 API 章節僅適用 React 19 以上;舊版必須略過該章節。

起手提示:裝好後貼給你的 agent,替換「」或 <> 裡的內容

依 composition-patterns 重構 <Composer.tsx>,把多個 boolean props 改成複合元件。

依原始 SKILL.md 整理,本站尚未進行任務實測。

安裝這個 skill

尚未確認此 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
)

實心圓點表示來源文件宣告支援該平台。安裝會取得來源的當前版本,可能與本站收錄版本不同;請先閱讀原始文件,確認執行權限與依賴需求。

收錄依據與使用條件

尚未進行任務實測
來源與依據
Vercel 維護的技能目錄,依原始文件整理用途。查看本次收錄版本
來源文件宣告的平台
來源未明列;尚待逐平台確認。來源說明

資料觀察:2026-11-02 · 中文介紹整理:2026-10-01 · 整個來源專案有 33,375 顆 GitHub stars(非此 skill 的評分或使用人數) · 中文介紹依據的原始版本

同族元素 · 跨平台開發與設計

使用教學

以下為上游 SKILL.md 原文:常見段落標題譯為中文,其餘保留英文。原文中的「工具本身的安裝」是指 skill 所用的套件或程式;把 skill 加進 agent 請看上方「安裝這個 skill」。

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/1a2c79d4e6c4a2283dc2c614b6538cbe1ed5ca62/skills/composition-patterns
Commit: 1a2c79d4e6c4a2283dc2c614b6538cbe1ed5ca62
Declared license: MIT
Mirror decision: recognized-open-license