组件组合设计
- 作者仓库星标 103,397
- 作者仓库 supabase
- 领域
- 工程开发
- 作者声明的智能体
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 运行环境证据
- 未执行;当前没有隔离运行测试证据
- 作者 / 版本 / 许可证
- @supabase · 未声明许可证
- 上下文用量评级
- 低消耗
- 接入复杂程度
- 即装即用
- 是否需要外部接口密钥
- 不需要
- 兼容的系统
- 未声明(默认跨平台)
- 运行环境要求
- 未检出明确要求
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
需要注意: 未声明工具权限范围;实际权限由运行环境决定。
# 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 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 these patterns if you're on 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`
章节与文件索引
按说明文件中的顺序排列。
何时申请
按优先级划分的规则类别
1. 组件架构(高)
2. 状态管理(中)
3. 实现模式(中)
文件/命令 -> architecture- · state- · patterns- · react19- · architecture-avoid-boolean-props · architecture-compound-components · state-decouple-implementation · state-context-interface
内容校验值 -> 82b7c5f9172a
当前原文的自动摘译,尚未人工审校。
何时申请
在以下情况下请参考这些指南: 使用许多布尔属性重构组件 构建可重用的组件库 设计灵活的组件 API 审查组件架构
按优先级划分的规则类别
优先级 · 类别 · 影响 · 前缀 1 · 组件架构 · 高 ·
architecture-2 · 状态管理 · 中 ·state-3 · 实现模式 · 中 ·patterns-4 · React 19 个 API · 中 ·react19-1. 组件架构(高)
architecture-avoid-boolean-props- 不要添加布尔属性来自定义行为;使用组合architecture-compound-components- 使用共享上下文构建复杂组件2. 状态管理(中)
state-decouple-implementation- 提供者是唯一知道如何管理状态的地方state-context-interface- 定义带有状态、操作、依赖注入元的通用接口state-lift-state- 将状态移动到提供者组件中以进行同级访问3. 实现模式(中)
patterns-explicit-variants- 创建显式变体组件而不是布尔模式patterns-children-over-render-props- 使用子组件而不是 renderX 道具进行组合