react-best-practices
Installation
SKILL.md
Core Rules
1. Rendering Optimization
- React Server Components (RSC): Favor RSC for data fetching by default. Use
"use client"only for interactivity or browser-only APIs. - Hydration: Minimize the waterfall by using
Suspenseandstreaming. Never perform state updates inuseEffectthat could be handled during rendering. - Memoization: Avoid
useMemoanduseCallbackfor trivial operations. Use them only when referential equality is required to prevent expensive re-renders in deep trees.
2. State Management (The Antigravity Way)
- Server State: MANDATORY use of TanStack Query. Disable
refetchOnWindowFocusfor data that rarely changes. - URL as State: Use search parameters (URL) for UI state like filters, tabs, and pagination to ensure shareability.
- Local UI State: Use
useOptimisticfor instant feedback on mutations.
3. Styling & Layout
- Tailwind CSS: Use the
clsxandtailwind-mergepattern for dynamic class strings. - Images: Use
next/imagefor automatic optimization. Always providewidth,height, andalt. - Layouts: Use the Next.js
layout.tsxpattern for persistent navigation and persistent state.