This skill makes the AI an expert in the React ecosystem, focusing on best practices, performance optimization (especially eliminating Waterfalls and reducing Bundle Size), and modern development patterns (Hooks, Server Components).
Core Capabilities
- React Hooks: Proficient in
useEffect(dependency management),useMemo/useCallback(performance optimization),useRef(DOM access/variable storage). - Next.js (App Router): Familiar with Server Components (RSC), Server Actions, Routing, Middleware.
- State Management: Recommend using Zustand or React Context for global state; use React Query/SWR for server state.
- Performance Optimization:
- Eliminate Waterfalls: Parallelize data fetching and avoid serial requests caused by overly deep component hierarchies.
- Reduce re-renders: Use
memo,useMemoappropriately, State Colocation. - Bundle Size: Use
React.lazyand dynamic imports for code splitting.
- TypeScript: Strongly typed Props, Hooks type definitions, Generic Components.
Best Practices Guide
Component Design
- Function components: Always prioritize function components + Hooks.
- Props types: Use TypeScript interface to define Props, avoid using
any。 - Single responsibility: Components should be as small as possible and focus on a single function.
Performance Optimization (recommended by Vercel & Callstack)
- Defer Await: Only in branches that truly need the data
await, avoid blocking unrelated logic. - Parallel requests: Use
Promise.allto handle independent asynchronous operations in parallel. - Server Components (RSC): Fetch data on the server as much as possible to reduce client-side JS bundle size and round-trip latency.
Common Pitfalls
- useEffect abuse: Avoid in
useEffectperforming unnecessary state synchronization (use derived state instead). - Missing dependencies:
useEffectanduseCallbackdependency arrays must be honest. - Context abuse: Avoid putting frequently changing data directly into Context, which causes full re-renders.
Common Command Reference
- Create project (Vite):
npm create vite@latest my-app -- --template react-ts - Create project (Next.js):
npx create-next-app@latest - Install common libraries:
pnpm add @tanstack/react-query zustand clsx tailwind-merge