react-patterns
React 18/19 hooks discipline, server/client component boundaries, Suspense + error boundaries, form actions, state management, and accessibility-first composition. Use when building or reviewing React/Next.js components.
- License 许可
- MIT
- 最近更新
- 2026-11-14
- Stars
- ★ 13
- Forks
- 2
01 前言 Front Matter
- name
- react-patterns
- source
- https://github.com/affaan-m/ECC
- license
- MIT
- description
- React 18/19 hooks discipline, server/client component boundaries, Suspense + error boundaries, form actions, state management, and accessibility-first composition. Use when building or reviewing React/Next.js components.
03 SKILL.md 正文
React Patterns
React 18/19 component patterns for correctness, performance, and maintainability.
Trigger phrases: "React component", "hooks", "server component", "RSC", "Suspense", "use client", "use server", "Next.js component"
Hook Discipline
// ✅ Stable dependency references
const handler = useCallback(() => doSomething(id), [id])
const value = useMemo(() => expensive(data), [data])
// ❌ New object/function every render → infinite loops
useEffect(() => {}, [{ id }]) // object literal in dep array
Rules of Hooks: only call at top level, never inside conditions/loops. Cleanup side effects: return cleanup from useEffect.
Server / Client Boundary
// Server Component (default in Next.js app/)
async function UserList() {
const users = await db.users.findMany()
return <ul>{users.map(u => <UserCard key={u.id} user={u} />)}</ul>
}
// Client Component — only when needed
'use client'
// Can: useState, useEffect, event handlers
// Cannot: async functions, server-only imports
Add 'use client' only for: interactive state, browser-only APIs, event listeners.
Suspense + Error Boundaries
<ErrorBoundary fallback={<ErrorCard />}>
<Suspense fallback={<Skeleton />}>
<UserProfile userId={id} />
</Suspense>
</ErrorBoundary>
Form Actions (React 19 / Next.js)
'use server'
async function createUser(formData: FormData) {
await db.users.create({ data: { name: formData.get('name') } })
revalidatePath('/users')
}
<form action={createUser}><input name="name" /><button type="submit">Create</button></form>
State Management
| Scope | Pattern |
|---|---|
| Component-local | useState / useReducer |
| Shared across tree | Context + useContext |
| Global / cross-page | Zustand / Jotai |
| Server state | TanStack Query / SWR |
| URL state | useSearchParams |
Anti-Fake-Pass
❌ useEffect with no cleanup for subscriptions → memory leak
❌ key={index} on list items that reorder
❌ Calling a hook inside an if/else → Rules of Hooks violation
❌ 'use client' on every component "to be safe"
❌ useState for derived data computable from other state
See Also
- react-performance, react-testing, core/agents/react-reviewer.md
04 同仓库更多 Skills
openai--sentry--sentry
Use when the user asks to inspect Sentry issues or events, summarize recent production errors, or pull basic Sentry health data via the Sentry API; perform read-only queries with the bundled script and require `SENTRY_AUTH_TOKEN`.
ito-basket-compare
Compare Itô prediction-market baskets against a user's knowledge base, portfolio notes, financial context, watchlist, or research thesis. Use for read-only basket comparison and gap analysis without investment advice or live trading.
implementing-network-traffic-baselining
Build network traffic baselines from NetFlow/IPFIX data using Python pandas for statistical analysis, z-score anomaly detection, and hourly/daily traffic pattern profiling
detecting-evasion-techniques-in-endpoint-logs
Detects defense evasion techniques used by adversaries in endpoint logs including log tampering, timestomping, process injection, and security tool disabling. Use when investigating suspicious endpoint behavior, building detection rules for evasion tactics, or conducting threat hunting for stealthy adversary activity. Activates for requests involving evasion detection, defense evasion analysis, log tampering detection, or MITRE ATT&CK TA0005.
implementing-microsegmentation-with-guardicore
Implementing microsegmentation using Akamai Guardicore Segmentation to map application dependencies, create granular network policies, visualize east-west traffic flows, and enforce least-privilege communication between workloads across data centers and cloud.
ramdisk-tmpfs-patterns
暂无简介