跳到正文
Skillpedia
网站与界面(前端)48k · #4224

composition-patterns

它能做什么

这个工具可以帮你更高效、更清晰地组织和构建软件组件。它会提出一些方法,让代码更易于管理,尤其是在项目不断变大的时候。

适用场景

  • ✓当一个组件有很多用来切换行为的“是/否”选项时。
  • ✓当你要创建一组可以在多处复用的组件时。
  • ✓当你在思考软件的不同部分该如何相互配合时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/composition-patterns/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/composition-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我怎样才能更好地组织界面组件,让它们更容易复用,也更容易理解?”

每周 5 个新技能,1 分钟读完。

工作原理

这个工具会分析你构建组件的方式,并推荐一些模式,比如把相关组件归为一组,或把重要信息放到一个集中的位置。这样就不必为每个组件设置大量单独的选项。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

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 Use

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 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

Limitations

  • Use this skill only when the task clearly matches the scope described above.
  • Do not treat the output as a substitute for environment-specific validation, testing, or expert review.
  • Stop and ask for clarification if required inputs, permissions, safety boundaries, or success criteria are missing.
常见问题

什么是 “boolean prop proliferation”?

指一个组件有太多用来改变其行为的“是”或“否”选项,导致使用起来变得复杂。

什么是 “compound components”(复合组件)?

指作为一个整体协同工作的组件,它们彼此共享信息和上下文,比如一个表单中多个相互通信的字段。

为什么组织组件很重要?

组织良好的组件更易于理解、使用和修改,能节省时间、减少错误,在大型项目中尤其如此。

详情

作者的原始描述

Use when working with composition-patterns tasks or workflows

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4224
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能