Official编程与开发github.com

vercel-组合模式

可扩展的 React 组合模式。在重构包含许多 props 的组件时使用。

vercel-组合模式 是什么?

该技能提供了一套 React 组合模式,用于构建灵活且易于维护的组件。它通过推荐使用复合组件、提升状态和内部组合等模式,避免布尔型 props 泛滥。这对于构建可重用组件库、设计灵活的组件 API 以及优化代码审查非常有帮助。技能将规则按优先级分为组件架构、状态管理、实现模式和 React 19 API 四个类别,并提供详细说明和代码示例。它适用于 Claude Code、Cursor、Codex 等 AI 编程助手,帮助开发者和 AI Agent 更好地理解和应用这些模式,提升代码质量和可扩展性。

兼容平台~Claude Code~Codex CLI~Cursor
Part ofReact
npx skills add https://github.com/vercel-labs/agent-skills/tree/main/skills/composition-patterns

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

React 组合模式

用于构建灵活、可维护的 React 组件的组合模式。避免通过使用复合组件、提升状态和组合内部实现来导致布尔型 props 泛滥。这些模式使代码库在扩展时更容易被人类和 AI 代理处理。

何时应用

在以下情况下参考这些指南:

  • 重构包含许多布尔型 props 的组件时
  • 构建可重用的组件库时
  • 设计灵活的组件 API 时
  • 审查组件架构时
  • 使用复合组件或 Context 提供者时

按优先级划分的规则类别

优先级类别影响前缀
1组件架构高architecture-
2状态管理中state-
3实现模式中patterns-
4React 19 API中react19-

快速参考

1. 组件架构 (高)

  • architecture-avoid-boolean-props - 不要添加布尔型 props 来自定义行为;应使用组合
  • architecture-compound-components - 使用共享 Context 构建复杂组件

2. 状态管理 (中)

  • state-decouple-implementation - Provider 是唯一知道状态管理方式的地方
  • state-context-interface - 定义包含状态、动作、元数据的通用接口,用于依赖注入
  • state-lift-state - 将状态提升到 Provider 组件中,以便兄弟组件可以访问

3. 实现模式 (中)

  • patterns-explicit-variants - 创建显式的变体组件,而不是使用布尔模式
  • patterns-children-over-render-props - 使用 children 进行组合,而不是使用 renderX props

4. React 19 API (中)

⚠️ 仅限 React 19+。 如果使用 React 18 或更早版本,请跳过此部分。

  • react19-no-forwardref - 不要使用 forwardRef;使用 use() 代替 useContext()

如何使用

阅读各个规则文件以获取详细说明和代码示例:

rules/architecture-avoid-boolean-props.md
rules/state-context-interface.md

每个规则文件包含:

  • 为什么重要的简要说明
  • 错误代码示例及解释
  • 正确代码示例及解释
  • 额外的上下文和参考信息

完整编译文档

有关包含所有规则的完整指南:AGENTS.md

Individual skills in this repo

This repo contains 11 individual skills — each has its own dedicated page.

deploy-to-vercel

Deploy applications and websites to Vercel. Use when the user requests deployment actions like "deploy my app", "deploy and give me the link", "push this live", or "create a preview deployment".

vercel-cli-with-tokens

Deploy and manage projects on Vercel using token-based authentication. Use when working with Vercel CLI using access tokens rather than interactive login — e.g.

vercel-labs/vercel-composition-patterns

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.

vercel-labs/vercel-react-best-practices

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

vercel-labs/vercel-react-native-skills

React Native and Expo best practices for building performant mobile apps. Use when building React Native components, optimizing list performance, implementing animations, or working with native modules. Triggers on tasks involving React Native, Expo, mobile performance, or native platform APIs.

vercel-labs/vercel-react-view-transitions

Guide for implementing smooth, native-feeling animations using React's View Transition API (`<ViewTransition>` component, `addTransitionType`, and CSS view transition pseudo-elements). Use this skill whenever the user wants to add page transitions, animate route changes, create shared element animations, animate enter/exit of components, animate list reorder, implement directional (forward/back) navigation animations, or integrate view transitions in Next.js. Also use when the user mentions view transitions, `startViewTransition`, `ViewTransition`, transition types, or asks about animating between UI states in React without third-party animation libraries.

vercel-optimize

Use for Vercel cost and performance optimization on deployed projects, especially Next.js, SvelteKit, Nuxt, and limited Astro apps. Collect Vercel metrics, usage, project config, and code scan results first; investigate only metric-backed candidates; produce ranked recommendations grounded in verified files and version-aware Vercel/framework docs. Trigger for Vercel bill reduction, slow or expensive routes, caching opportunities, Function Invocations, Build Minutes, Fast Data Transfer, Core Web Vitals, Bot Management, Fluid compute, or cost breakdown requests.

vercel-react-best-practices

React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.

vercel-react-native-skills

React Native and Expo best practices for building performant mobile apps. Use

web-design-guidelines

Review UI code for Web Interface Guidelines compliance. Use when asked to

writing-guidelines

Review docs/prose for Writing Guidelines compliance. Use when asked to

相关技能