React 组件组合模式实践
vercel-composition-patterns
可扩展的 React 组合模式。当重构存在布尔属性泛滥的组件、构建灵活的组件库或设计可复用 API 时使用。适用于涉及复合组件、渲染属性(render props)、上下文提供者(context providers)或组件架构的任务。包含 React 19 的 API 变更。
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- vercel-composition-patterns
- license
- MIT
- metadata
- { "author": "vercel", "version": "1.0.0" }
- description
- React composition patterns that scale. Use when refactoring components with boolean prop proliferation, building flexible component libraries, or designing reusable APIs. Triggers on tasks involving compound components, render props, context providers, or component architecture. Includes React 19 API changes.
02 资源文件 14
- 参考文档AGENTS.md22.1 KB
- 参考文档metadata.json530 B
- 参考文档README.md2.1 KB
- 参考文档rules/_sections.md829 B
- 参考文档rules/_template.md329 B
- 参考文档rules/architecture-avoid-boolean-props.md2.2 KB
- 参考文档rules/architecture-compound-components.md2.5 KB
- 参考文档rules/patterns-children-over-render-props.md1.8 KB
- 参考文档rules/patterns-explicit-variants.md2.3 KB
- 参考文档rules/react19-no-forwardref.md953 B
- 参考文档rules/state-context-interface.md4.9 KB
- 参考文档rules/state-decouple-implementation.md2.6 KB
- 参考文档rules/state-lift-state.md3.1 KB
- 参考文档skill.meta.json191 B
03 SKILL.md 正文
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
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Component Architecture | HIGH | architecture- |
| 2 | State Management | MEDIUM | state- |
| 3 | Implementation Patterns | MEDIUM | patterns- |
| 4 | React 19 APIs | MEDIUM | react19- |
Quick Reference
1. Component Architecture (HIGH)
architecture-avoid-boolean-props- Don't add boolean props to customize behavior; use compositionarchitecture-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 managedstate-context-interface- Define generic interface with state, actions, meta for dependency injectionstate-lift-state- Move state into provider components for sibling access
3. Implementation Patterns (MEDIUM)
patterns-explicit-variants- Create explicit variant components instead of boolean modespatterns-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 useforwardRef; useuse()instead ofuseContext()
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
04 同仓库更多 Skills
Excel 电子表格处理
xlsx
当电子表格文件是主要输入或输出时,使用本技能。即用户想要执行以下任意任务:打开、读取、编辑或修复现有的 .xlsx、.xlsm、.xltx、.csv 或 .tsv 文件(例如添加列、计算公式、设置格式、制作图表、清理杂乱数据);从零开始或从其他数据源创建新的电子表格;或在表格文件格式之间进行转换。尤其当用户按名称或路径提及某个电子表格文件时触发——即使是随意提及(如“我下载文件夹里的 xlsx”)——并希望对其进行处理或从中生成内容。也适用于将杂乱的表格数据文件(格式错误的数据行、错位的表头、垃圾数据)清理或重组为规范的电子表格。交付物必须是电子表格文件。当主要交付物是 Word 文档、HTML 报告、独立的 Python 脚本、数据库管道或 Google Sheets API 集成时,不要触发,即使涉及表格数据。
Web 应用自动化测试工具
webapp-testing
使用 Playwright 与本地 Web 应用程序进行交互和测试的工具包。支持验证前端功能、调试 UI 行为、捕获浏览器截图以及查看浏览器日志。
Web 工件构建工具
web-artifacts-builder
一套工具,用于使用现代前端 Web 技术(React、Tailwind CSS、shadcn/ui)创建精细的、多组件的 claude.ai HTML 工件。适用于需要状态管理、路由或 shadcn/ui 组件的复杂工件,不适用于简单的单文件 HTML/JSX 工件。
作品主题样式设置
theme-factory
用于为作品应用主题样式的工具包。这些作品可以是幻灯片、文档、报告、HTML 落地页等。提供 10 个包含颜色和字体的预设主题,可应用于任何已创建的作品,也可以即时生成新主题。
Slack 动图 GIF 制作
slack-gif-creator
用于创建针对 Slack 优化的动画 GIF 的知识和工具。提供相关约束条件、验证工具和动画概念。当用户请求制作用于 Slack 的动画 GIF 时使用,例如“帮我做一个 X 做 Y 的 GIF 用于 Slack”。
技能创建与优化
skill-creator
创建新技能、修改和改进现有技能,并衡量技能性能。当用户想要从零开始创建技能、编辑或优化现有技能、运行评测以测试技能、通过方差分析对技能性能进行基准测试,或优化技能描述以提高触发准确率时使用。