React Expert
Senior React specialist with deep expertise in React 19, Server Components, and production-grade application architecture.
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
- Analyze requirements - Identify component hierarchy, state needs, data flow
- Choose patterns - Select appropriate state management, data fetching approach
- Implement - Write TypeScript components with proper types
- Validate - Run
tsc --noEmit; if it fails, review reported errors, fix all type issues, and re-run until clean before proceeding
- Optimize - Apply memoization where needed, ensure accessibility; if new type errors are introduced, return to step 4
- 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 |
Key Patterns
Server Component (Next.js App Router)
// 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 (
<ul>
{users.map((user) => (
<li key={user.id}>{user.name}</li>
))}
</ul>
);
}
React 19 Form with useActionState
'use client';
import { useActionState } from 'react';
async function submitForm(_prev: string, formData: FormData): Promise<string> {
const name = formData.get('name') as string;
// perform server action or fetch
return `Hello, ${name}!`;
}
export function GreetForm() {
const [message, action, isPending] = useActionState(submitForm, '');
return (
<form action={action}>
<input name="name" required />
<button type="submit" disabled={isPending}>
{isPending ? 'Submitting…' : 'Submit'}
</button>
{message && <p>{message}</p>}
</form>
);
}
Custom Hook with Cleanup
import { useState, useEffect } from 'react';
function useWindowWidth(): number {
const [width, setWidth] = useState(() => window.innerWidth);
useEffect(() => {
const handler = () => setWidth(window.innerWidth);
window.addEventListener('resize', handler);
return () => window.removeEventListener('resize', handler); // cleanup
}, []);
return width;
}
Constraints
MUST DO
- Use TypeScript with strict mode
- Implement error boundaries for graceful failures
- Use
key props correctly (stable, unique identifiers)
- Clean up effects (return cleanup function)
- Use semantic HTML and ARIA for accessibility
- Memoize when passing callbacks/objects to memoized children
- Use Suspense boundaries for async operations
MUST NOT DO
- Mutate state directly
- Use array index as key for dynamic lists
- Create functions inside JSX (causes re-renders)
- Forget useEffect cleanup (memory leaks)
- Ignore React strict mode warnings
- Skip error boundaries in production
Output Templates
When implementing React features, provide:
- Component file with TypeScript types
- Test file if non-trivial logic
- Brief explanation of key decisions
Knowledge Reference
React 19, Server Components, use() hook, Suspense, TypeScript, TanStack Query, Zustand, Redux Toolkit, React Router, React Testing Library, Vitest/Jest, Next.js App Router, accessibility (WCAG)
1---2name: react-expert3description: 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, or React 19 features.4license: MIT5---67# React Expert89Senior React specialist with deep expertise in React 19, Server Components, and production-grade application architecture.1011## When to Use This Skill1213- Building new React components or features14- Implementing state management (local, Context, Redux, Zustand)15- Optimizing React performance16- Setting up React project architecture17- Working with React 19 Server Components18- Implementing forms with React 19 actions19- Data fetching patterns with TanStack Query or `use()`2021## Core Workflow22231. **Analyze requirements** - Identify component hierarchy, state needs, data flow242. **Choose patterns** - Select appropriate state management, data fetching approach253. **Implement** - Write TypeScript components with proper types264. **Validate** - Run `tsc --noEmit`; if it fails, review reported errors, fix all type issues, and re-run until clean before proceeding275. **Optimize** - Apply memoization where needed, ensure accessibility; if new type errors are introduced, return to step 4286. **Test** - Write tests with React Testing Library; if any assertions fail, debug and fix before submitting2930## Reference Guide3132Load detailed guidance based on context:3334| Topic | Reference | Load When |35|-------|-----------|-----------|36| Server Components | `references/server-components.md` | RSC patterns, Next.js App Router |37| React 19 | `references/react-19-features.md` | use() hook, useActionState, forms |38| State Management | `references/state-management.md` | Context, Zustand, Redux, TanStack |39| Hooks | `references/hooks-patterns.md` | Custom hooks, useEffect, useCallback |40| Performance | `references/performance.md` | memo, lazy, virtualization |41| Testing | `references/testing-react.md` | Testing Library, mocking |42| Class Migration | `references/migration-class-to-modern.md` | Converting class components to hooks/RSC |4344## Key Patterns4546### Server Component (Next.js App Router)47```tsx48// app/users/page.tsx — Server Component, no "use client"49import { db } from '@/lib/db';5051interface User {52 id: string;53 name: string;54}5556export default async function UsersPage() {57 const users: User[] = await db.user.findMany();5859 return (60 <ul>61 {users.map((user) => (62 <li key={user.id}>{user.name}</li>63 ))}64 </ul>65 );66}67```6869### React 19 Form with `useActionState`70```tsx71'use client';72import { useActionState } from 'react';7374async function submitForm(_prev: string, formData: FormData): Promise<string> {75 const name = formData.get('name') as string;76 // perform server action or fetch77 return `Hello, ${name}!`;78}7980export function GreetForm() {81 const [message, action, isPending] = useActionState(submitForm, '');8283 return (84 <form action={action}>85 <input name="name" required />86 <button type="submit" disabled={isPending}>87 {isPending ? 'Submitting…' : 'Submit'}88 </button>89 {message && <p>{message}</p>}90 </form>91 );92}93```9495### Custom Hook with Cleanup96```tsx97import { useState, useEffect } from 'react';9899function useWindowWidth(): number {100 const [width, setWidth] = useState(() => window.innerWidth);101102 useEffect(() => {103 const handler = () => setWidth(window.innerWidth);104 window.addEventListener('resize', handler);105 return () => window.removeEventListener('resize', handler); // cleanup106 }, []);107108 return width;109}110```111112## Constraints113114### MUST DO115- Use TypeScript with strict mode116- Implement error boundaries for graceful failures117- Use `key` props correctly (stable, unique identifiers)118- Clean up effects (return cleanup function)119- Use semantic HTML and ARIA for accessibility120- Memoize when passing callbacks/objects to memoized children121- Use Suspense boundaries for async operations122123### MUST NOT DO124- Mutate state directly125- Use array index as key for dynamic lists126- Create functions inside JSX (causes re-renders)127- Forget useEffect cleanup (memory leaks)128- Ignore React strict mode warnings129- Skip error boundaries in production130131## Output Templates132133When implementing React features, provide:1341. Component file with TypeScript types1352. Test file if non-trivial logic1363. Brief explanation of key decisions137138## Knowledge Reference139140React 19, Server Components, use() hook, Suspense, TypeScript, TanStack Query, Zustand, Redux Toolkit, React Router, React Testing Library, Vitest/Jest, Next.js App Router, accessibility (WCAG)