Structure React components with clear props, hooks, composition, and colocation. Use when React components, hooks, props, colocation, compound components, React 组件, 组件结构, custom hooks, or when reviewing React UI structure. Pairs with code-quality-standards; does not replace repo React conventions, ESLint, or design systems.
Instalar com Codex ou Claude Copie este prompt, cole no Codex, Claude ou outro assistente e deixe que ele revise a página da skill e instale para você.
Um comando direto ignora o prompt de revisão. Verifique a origem antes de executá-lo.
Instruções da origem · Visualização somente leitura
name
react-component-patterns
description
Structure React components with clear props, hooks, composition, and colocation. Use when React components, hooks, props, colocation, compound components, React 组件, 组件结构, custom hooks, or when reviewing React UI structure. Pairs with code-quality-standards; does not replace repo React conventions, ESLint, or design systems.
React Component Patterns
Engineering patterns for React component structure: what owns state, how
props and hooks stay readable, how files are colocated, and how composition
beats prop-drilling soup. Prefer the repo’s existing React style (RSC vs CSR,
folder layout, design system) over inventing a second model.
Use When
Building or refactoring React / React Native components
Designing props APIs, children/slots, or compound components
State stack already chosen: React Query/SWR, Redux, Zustand, Context —
route client/server state decisions to state-management-guidelines
Styling system: CSS Modules, Tailwind, styled-components, vanilla-extract —
match local pattern; do not introduce a second system mid-PR
Neighboring components: copy 2–3 mature feature components for props
shape, error/loading UI, and hook extraction thresholds
Precedence: If repo rules conflict with defaults below, follow the repo.
Surface conflicts that break hooks rules, leak secrets to the client, or mix
server/client boundaries incorrectly.
Workflow
State the UI contract.
What the user sees/does; loading, empty, error, success
Controlled vs uncontrolled inputs; who owns which slice of state
Server vs client responsibility (RSC data, client interactivity)
Compose before you configure.
Prefer small components + children/slots over giant prop matrices
Lift state only as far as shared consumers need it
Ignore cancellation (see async-concurrency-patterns)
Keep one concern per hook
useGodObject that fetches, caches, and formats everything
Colocation map (typical)
features/orders/
OrderList.tsx
OrderList.test.tsx
OrderList.module.css # or co-located Tailwind usage
useOrderFilters.ts # private to feature until reused
api.ts # feature fetchers if not global
Promote useOrderFilters to shared/hooks/ only when a second feature needs it.
Server vs client (React 19 / Next-style)
Default to Server Components for static/data display when the stack supports it
Add "use client" only for state, effects, browser APIs, or event handlers
Pass serializable props across the server→client boundary; no functions/classes
unless the framework explicitly supports that pattern
Do not fetch secrets or privileged tokens in client components
functionuseDashboard(userId?: string) {
if (!userId) returnnull; // Bad: breaks rules of hooks for callers who branchconst [user, setUser] = useState(null);
const [theme, setTheme] = useState("light");
// fetches, websockets, form state all in one…
}
Client vs server state, Redux/Zustand/context choice
state-management-guidelines
this for component wiring
Production correctness, errors, resources, tests, security
code-quality-standards
always apply on implementation
TS/ESLint style only
typescript-style-and-eslint
this for component shape
Visual design / aesthetics
frontend-design / top-design
this for structure
Async cancel, stale responses, fan-out
async-concurrency-patterns
this for where hooks live
Naming components/hooks/files
naming-conventions-general
this for structure
Comments on non-obvious UI invariants
comment-writing-standards
—
Routing to code-quality-standards
Keep this skill primary for React structure and composition. Always apply
code-quality-standards as the implementation baseline when code changes:
Clear boundaries: UI vs data access vs domain rules
Error and loading states handled; no swallowed failures in event handlers
Subscriptions, timers, and listeners cleaned up on unmount
Untrusted input (URL, form, postMessage) validated at the boundary
Tests for critical interaction paths when blast radius warrants
No secrets in client bundles or logs
This skill specializes components, hooks, props, and colocation. It does not
replace general quality, security, state-library choice, or visual design systems.