react-best-practices
React best-practices reviewer for TSX files. Triggers after editing multiple TSX components to run a condensed quality checklist covering component structure, hooks usage, accessibility, performance, and TypeScript patterns.
- License 许可
- MIT
- 最近更新
- 2026-03-30
- Stars
- ★ 2
- Forks
- 0
01 前言 Front Matter
- name
- react-best-practices
- chainTo
- [ { "message": "Client-side axios detected — loading SWR guidance for React data fetching with caching and revalidation.", "pattern": "from\\s+['\\\"](axios)['\"]|axios\\.(get|post|put|delete)\\(", "targetSkill": "swr" }, { "message": "Legacy CSS-in-JS or component library detected — loading shadcn/ui guidance for modern Vercel-native UI.", "pattern": "from\\s+['\\\"](styled-components|@emotion/styled|@emotion/react|@mui/material|@chakra-ui/react)['\"]|styled\\.", "targetSkill": "shadcn" }, { "message": "Manual fetch().then() in component — loading SWR guidance for declarative data fetching with caching and revalidation.", "pattern": "fetch\\s*\\([^)]*\\)\\s*\\.then\\s*\\(|\\.then\\s*\\(\\s*(res|response)\\s*=>", "targetSkill": "swr", "skipIfFileContains": "useSWR|from\\s+['\"\"](swr)['\"\"]|useQuery|@tanstack/react-query" } ]
- metadata
- { "docs": [ "https://react.dev/reference/react", "https://react.dev/learn" ], "priority": 4, "bashPatterns": [], "pathPatterns": [ "src/components/**/*.tsx", "src/components/**/*.jsx", "app/components/**/*.tsx", "app/components/**/*.jsx", "components/**/*.tsx", "components/**/*.jsx", "src/ui/**/*.tsx", "lib/components/**/*.tsx" ], "importPatterns": [ "react", "react-dom" ] }
- validate
- [ { "message": "Client-side axios detected. Use SWR for React data fetching with caching, revalidation, and deduplication.", "pattern": "from\\s+['\"](axios)['\"]|axios\\.(get|post|put|delete)\\(", "severity": "recommended", "upgradeWhy": "Replace manual fetch/axios with SWR for automatic caching, revalidation, and optimistic UI.", "upgradeToSkill": "swr", "skipIfFileContains": "useSWR|from\\s+['\"](swr)['\"]|@tanstack/react-query" }, { "message": "Legacy CSS-in-JS or component library detected. Consider shadcn/ui + Tailwind for modern Vercel-native UI.", "pattern": "from\\s+['\"](styled-components|@emotion/styled|@emotion/react|@mui/material|@chakra-ui/react)['\"]|styled\\.", "severity": "warn", "upgradeWhy": "Migrate from CSS-in-JS/MUI/Chakra to shadcn/ui + Tailwind CSS for better SSR performance and Vercel ecosystem alignment.", "upgradeToSkill": "shadcn", "skipIfFileContains": "@/components/ui|shadcn|tailwindcss" } ]
- retrieval
- { "aliases": [ "react review", "component quality", "tsx linter", "react patterns" ], "intents": [ "review react code", "improve component quality", "check accessibility", "optimize react" ], "entities": [ "hooks", "accessibility", "React", "TSX", "component" ] }
- description
- React best-practices reviewer for TSX files. Triggers after editing multiple TSX components to run a condensed quality checklist covering component structure, hooks usage, accessibility, performance, and TypeScript patterns.
03 SKILL.md 正文
React Best-Practices Review
After editing several TSX/JSX files, run through this condensed checklist to catch common issues before they compound.
Component Structure
- One component per file — colocate helpers only if they are private to that component
- Named exports over default exports for better refactoring and tree-shaking
- Props interface defined inline or colocated, not in a separate
types.tsunless shared - Destructure props in the function signature:
function Card({ title, children }: CardProps) - Avoid barrel files (
index.tsre-exports) in large projects — they hurt tree-shaking
Hooks
- Rules of Hooks — never call hooks conditionally or inside loops
- Custom hooks — extract reusable logic into
use*functions when two or more components share it - Dependency arrays — list every reactive value; lint with
react-hooks/exhaustive-deps useCallback/useMemo— use only when passing to memoized children or expensive computations, not by defaultuseEffectcleanup — return a cleanup function for subscriptions, timers, and abort controllers
State Management
- Colocate state — keep state as close as possible to where it is consumed
- Derive, don't sync — compute values from existing state instead of adding
useEffectto mirror state - Avoid prop drilling past 2–3 levels — use context or composition (render props / children)
- Server state — use React Query, SWR, or Server Components instead of manual fetch-in-effect
Accessibility (a11y)
- Semantic HTML first — use
<button>,<a>,<nav>,<main>, etc. before reaching for<div onClick> alton every<img>— decorative images getalt=""- Keyboard navigation — interactive elements must be focusable and operable via keyboard
aria-*attributes — only when native semantics are insufficient; don't redundantly label
Performance
React.memo— wrap pure display components that re-render due to parent changes- Lazy loading — use
React.lazy+Suspensefor route-level code splitting - List keys — use stable, unique IDs; never use array index as key for reorderable lists
- Avoid inline object/array literals in JSX props — they create new references every render
- Image optimization — use
next/imageor responsivesrcSet; avoid unoptimized<img>in Next.js
TypeScript Patterns
React.FCis optional — prefer plain function declarations with explicit return typesPropsWithChildren— use when the component acceptschildrenbut has no other custom props- Event handlers — type as
React.MouseEvent<HTMLButtonElement>, notany - Generics for reusable components — e.g.,
function List<T>({ items, renderItem }: ListProps<T>) as constfor config objects — ensures literal types for discriminated unions and enums
Design System Consistency
- Prefer shadcn primitives in Vercel-stack apps: Button, Input, Tabs, Dialog, AlertDialog, Sheet, Table, Card before building ad-hoc equivalents.
- Reject container soup: repeated
div rounded-xl border p-6blocks usually mean stronger composition primitives are missing. - Typography consistency: use Geist Sans and Geist Mono consistently; reserve monospace for code, metrics, IDs, and timestamps.
Review Workflow
- Scan recent TSX edits for the patterns above
- Flag any violations with file path and line reference
- Suggest minimal fixes — do not refactor beyond what is needed
- If multiple issues exist in one file, batch them into a single edit
04 同仓库更多 Skills
workflow
Vercel Workflow DevKit (WDK) expert guidance. Use when building durable workflows, long-running tasks, API routes or agents that need pause/resume, retries, step-based execution, or crash-safe orchestration with Vercel Workflow.
verification
Full-story verification — infers what the user is building, then verifies the complete flow end-to-end: browser → API → data → response. Triggers on dev server start and 'why isn't this working' signals.
vercel-storage
Vercel storage expert guidance — Blob, Edge Config, and Marketplace storage (Neon Postgres, Upstash Redis). Use when choosing, configuring, or using data storage with Vercel applications.
vercel-services
Vercel Services — deploy multiple services within a single Vercel project. Use for monorepo layouts or when combining a backend (Python, Go) with a frontend (Next.js, Vite) in one deployment.
vercel-sandbox
Vercel Sandbox guidance — ephemeral Firecracker microVMs for running untrusted code safely. Supports AI agents, code generation, and experimentation. Use when executing user-generated or AI-generated code in isolation.
vercel-queues
Vercel Queues guidance (public beta) — durable event streaming with topics, consumer groups, retries, and delayed delivery. $0.60/1M ops. Powers Workflow DevKit. Use when building async processing, fan-out patterns, or event-driven architectures.