--- name: react-expert description: Use when building React 18+ applications in .jsx or .tsx files, Next.js App Router projects, or create-react-app setups. Creates components, implements custom hooks, debugs rendering issues, migrates class components to functional, and implements state management. Invoke for Server Components, Suspense boundaries, useActionState forms, performance optimization, React 19 features, accessibility (WCAG 2.1 AA), or design system adherence. license: MIT metadata: author: https://github.com/vinhio version: "1.2.0" domain: frontend role: specialist scope: implementation output-format: code related-skills: fullstack-guardian, playwright-expert, test-master autoInvoke: true priority: high triggers: - "react" - "jsx" - "hooks" - "useState" - "useEffect" - "useContext" - "server components" - "react 19" - "suspense" - "tanstack query" - "redux" - "zustand" - "component" - "frontend" - "accessibility" - "wcag" - "aria" - "design system" allowed-tools: Read, Grep, Glob, Edit, Write --- # React Expert Senior React specialist with deep expertise in React 19, Server Components, and production-grade application architecture. ## Table of Contents - [When to Use This Skill](#when-to-use-this-skill) - [Core Workflow](#core-workflow) - [Reference Guide](#reference-guide) - [Key Patterns](#key-patterns) - [Constraints](#constraints) - [Output Templates](#output-templates) - [Knowledge Reference](#knowledge-reference) ## When to Use This Skill - Building new React components or features - Implementing state management (local, Context, Redux, Zustand) - Optimizing React performance - Setting up React project architecture - Working with React 19 Server Components - Implementing forms with React 19 actions - Data fetching patterns with TanStack Query or `use()` ## Core Workflow 1. **Analyze requirements** - Identify component hierarchy, state needs, data flow 2. **Choose patterns** - Select appropriate state management, data fetching approach 3. **Implement** - Write TypeScript components with proper types 4. **Validate** - Run `tsc --noEmit`; if it fails, review reported errors, fix all type issues, and re-run until clean before proceeding 5. **Optimize** - Apply memoization where needed, ensure accessibility; if new type errors are introduced, return to step 4 6. **Test** - Write tests with React Testing Library; if any assertions fail, debug and fix before submitting ## Reference Guide Load detailed guidance based on context: | Topic | Reference | Load When | | --------------------------- | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Server Components | `references/server-components.md` | RSC patterns, Next.js App Router | | React 19 | `references/react-19-features.md` | use() hook, useActionState, forms | | State Management | `references/state-management.md` | Context, Zustand, Redux, TanStack | | Hooks | `references/hooks-patterns.md` | Custom hooks, useEffect, useCallback | | Performance | `references/performance.md` | memo, lazy, virtualization | | Testing | `references/testing-react.md` | Testing Library, mocking | | Class Migration | `references/migration-class-to-modern.md` | Converting class components to hooks/RSC | | Coding Guide | `references/coding-guide.md` | Providers, routing/guards, store, layouts, screens, components, hooks, styles/assets, naming conventions, region markers/JSX annotations, domain models | | Refactoring Large Files | `references/refactoring-large-files.md` | Splitting an oversized component/hook/file, grouping a feature directory into folders, ref-ownership rules, verifying a split didn't change behavior | | Component Design Principles | `references/component-design-principles.md` | Feature-based folder organization, file colocation, pure rendering, no side effects in render, rules of hooks, single layer of abstraction, props/forwardRef, compound components, state hoisting | | Accessibility | `references/accessibility.md` | Keyboard navigation, ARIA labels, focus management, empty/error states, WCAG verification checklist | | Forms & Error Handling | `references/forms-and-error-handling.md` | Controlled forms, React Hook Form + Zod, error boundaries, safe conditional rendering, list-key pitfalls | | Design System Adherence | `references/design-system-adherence.md` | Avoiding the generic "AI aesthetic", spacing/typography/color tokens, responsive breakpoints, skeleton loading, optimistic updates | ## Key Patterns ### Server Component (Next.js App Router) ```tsx // app/users/page.tsx — Server Component, no "use client" import { db } from "@/lib/db"; interface User { id: string; name: string; } export default async function UsersPage() { const users: User[] = await db.user.findMany(); return (