用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill component-design-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Bun runtime: HTTP server, file I/O, SQLite, test runner, package manager, bundler — all-in-one JS toolchain.
Clerk: Drop-in auth UI, Organizations, User management, JWT templates, webhooks, Next.js middleware integration.
Gelişmiş masaüstü, tarayıcı ve işletim sistemi kontrol yeteneği. Görsel (koordinat tabanlı) fare/klavye otomasyonu, DOM manipülasyonu, pencere yönetimi, gelişmiş dosya, ağ ve süreç yönetimini kapsar.
基于 SOC 职业分类
正在显示 SKILL.md
| name | component-design-patterns |
| description | Component design: Atomic design, composition, prop design, state placement. |
| triggers | {"extensions":[".tsx",".jsx"],"directories":["components/","ui/"],"keywords":["component","props","composition","compound","atomic","slot"]} |
| auto_load_when | Designing or editing React components |
| agent | frontend-ops |
| tools | ["Read","Write","Bash"] |
Focus: Design principles, composition, reusability
When to split components:
├── Component does too much
│ └── Multiple responsibilities
│ └── Hard to test
│ └── Can describe in one sentence?
│
├── Component is reused in multiple places
│ └── But with different content
│ └── Props control everything
│ └── Use children/slots instead
│
├── Component renders different states
│ └── Loading, error, empty, data
│ └── Extract each to separate component
│
└── Component is hard to maintain
└── 200+ lines
└── Multiple concerns
└── Several reasons to change
When NOT to split:
├── Components are tightly coupled
│ └── Always used together
│ └── Split would make harder
│
├── Premature abstraction
│ └── Not used anywhere else yet
│ └── Wait until second use
│
└── Simplicity is priority
└── Over-abstraction = complexity
└── Trade-off: balance needed
Props principles:
├── Explicit over implicit
└── Name clearly indicates purpose
└── Avoid: data, value, params
│
├── Prefer objects over primitives
└── Related props together
└── Easier to extend
│
├── Boolean props
└── Use sparingly
└── Better: explicit prop for state
└── Example: isLoading vs loadingState
│
└── Callbacks: verb prefix
└── onClick, onSubmit, onLogin
└── Past tense for handlers: onDataFetched
When to use children:
├── Content is component's responsibility
└── Button with icon + text
└── Card with header/body/footer
│
├── Content varies from caller
└── Not predictable props
└── Use slots for flexibility
│
└── When NOT to use children:
└── Simple data display
└── Predictable content
└── Props more explicit
How to compose:
├── Wrapper components
└── Layout: margin, padding, max-width
└── Applies container rules
└── Children are content
│
├── Slot components
└── Card with header/body/footer slots
└── Optional sections
└── Caller controls what's where
│
└── Higher-order components (use carefully)
└── Add behavior (loading, error)
└── Compose multiple behaviors
└── Hooks often better alternative
Composition vs inheritance:
├── Composition preferred
└── Flexible, interchangeable
└── Props control behavior
└── Easy to test
│
└── Inheritance:
└── Avoid for UI components
└── Tight coupling
└── Hard to override
└── Use composition instead
When to use each level:
├── Atoms (basic elements)
└── Button, Input, Label
└── Smallest reusable units
└── No dependencies on other components
│
├── Molecules (simple groups)
└── FormField (Label + Input)
&& SearchBar (Input + Button)
&& Consistent units working together
│
├── Organisms (complex UI)
&& Header, Sidebar, ProductCard
&& Distinct section of UI
&& Multiple molecules/atoms
│
├── Templates (page structure)
&& Layout, ArticleTemplate
&& Blueprint for pages
&& Placeholders for content
│
└── Pages (full templates)
&& HomePage, ProductPage
&& Instantiated templates
&& Connect to data, state
Where to put state:
├── Component-local state
└── useState for UI state
└── Only used in this component
└── Not passed elsewhere
│
├── Shared state (lift up)
└── Used by multiple children
└── Closest common ancestor
└── Pass down via props or context
│
├── Global state
└── Many components need access
&& User session, theme
&& Use: Zustand, Context
│
└── Server state
&& API data
&& Use: React Query, SWR
&& NOT component state
❌ Component that does data fetching + rendering + state management
✅ Single responsibility: container (data) vs presentational (UI)
❌ Props drilling 5 levels deep
✅ Composition pattern or context for cross-cutting concerns
❌ Boolean prop explosion (isLoading, isDisabled, isError, isLarge...)
✅ Variant prop with discriminated union: variant="loading" | "error"
❌ Ref forwarding broken by wrapping in HOC
✅ forwardRef at every wrapper; compose with mergeRefs
❌ Component accepting 20+ props
✅ Split component; use render props or compound components for complexity
| Pattern | Use case | Trade-off |
|---|---|---|
| Compound components | Complex related UI | Flexible but verbose API |
| Render props | Injecting behavior | More flexible than HOC |
| HOC | Cross-cutting (auth, analytics) | Hard to compose |
| Custom hook | Reusable logic only | No rendering |
Polymorphic as prop | Semantic element flex | Type complexity |
| Slot pattern | Content projection | Like Vue slots in React |