React Best Practices
React and Next.js performance optimization guidelines from Vercel Engineering. 57 rules across 8 categories for writing, reviewing, and refactoring React code.
React and Next.js performance optimization guidelines from Vercel Engineering. 57 rules across 8 categories for writing, reviewing, and refactoring React code.
Real data. Real impact.
Emerging
Developers
Per week
Open source
Skills give you superpowers. Install in 30 seconds.
Comprehensive performance optimization guide for React and Next.js applications from Vercel Engineering. Contains 57 rules across 8 categories, prioritized by impact.
npx clawhub@latest install react-best-practices
Provides actionable rules for:
react performance, nextjs optimization, bundle size, waterfalls, suspense, server components, rsc, rerender, usememo, dynamic import, parallel fetching, cache, swr
| Priority | Category | Impact | Rule Prefix |
|---|---|---|---|
| 1 | Eliminating Waterfalls | CRITICAL | |
| 2 | Bundle Size Optimization | CRITICAL | |
| 3 | Server-Side Performance | HIGH | |
| 4 | Client-Side Data Fetching | MEDIUM-HIGH | |
| 5 | Re-render Optimization | MEDIUM | |
| 6 | Rendering Performance | MEDIUM | |
| 7 | JavaScript Performance | LOW-MEDIUM | |
| 8 | Advanced Patterns | LOW | |
| Rule | Description |
|---|---|
| Move await into branches where actually used |
| Use for independent operations |
| Use better-all for partial dependencies |
| Start promises early, await late in API routes |
| Use Suspense to stream content |
| Rule | Description |
|---|---|
| Import directly, avoid barrel files |
| Use for heavy components |
| Load analytics/logging after hydration |
| Load modules only when feature is activated |
| Preload on hover/focus for perceived speed |
| Rule | Description |
|---|---|
| Authenticate server actions like API routes |
| Use for per-request dedup |
| Use LRU cache for cross-request caching |
| Avoid duplicate serialization in RSC props |
| Minimize data passed to client components |
| Restructure components to parallelize fetches |
| Use for non-blocking operations |
| Rule | Description |
|---|---|
| Use SWR for automatic request deduplication |
| Deduplicate global event listeners |
| Use passive listeners for scroll |
| Version and minimize localStorage data |
| Rule | Description |
|---|---|
| Don't subscribe to state only used in callbacks |
| Extract expensive work into memoized components |
| Hoist default non-primitive props |
| Use primitive dependencies in effects |
| Subscribe to derived booleans, not raw values |
| Derive state during render, not effects |
| Use functional setState for stable callbacks |
| Pass function to useState for expensive values |
| Avoid memo for simple primitives |
| Put interaction logic in event handlers |
| Use startTransition for non-urgent updates |
| Use refs for transient frequent values |
| Rule | Description |
|---|---|
| Animate div wrapper, not SVG element |
| Use content-visibility for long lists |
| Extract static JSX outside components |
| Reduce SVG coordinate precision |
| Use inline script for client-only data |
| Suppress expected mismatches |
| Use Activity component for show/hide |
| Use ternary, not && for conditionals |
| Prefer useTransition for loading state |
| Rule | Description |
|---|---|
| Group CSS changes via classes or cssText |
| Build Map for repeated lookups |
| Cache object properties in loops |
| Cache function results in module-level Map |
| Cache localStorage/sessionStorage reads |
| Combine multiple filter/map into one loop |
| Check array length before expensive ops |
| Return early from functions |
| Hoist RegExp creation outside loops |
| Use loop for min/max instead of sort |
| Use Set/Map for O(1) lookups |
| Use toSorted() for immutability |
| Rule | Description |
|---|---|
| Store event handlers in refs |
| Initialize app once per app load |
| useLatest for stable callback refs |
Each rule file in
rules/ contains:
rules/async-parallel.md rules/bundle-barrel-imports.md rules/rerender-memo.md
For the complete guide with all rules expanded:
AGENTS.md
This 2900+ line document contains every rule with full code examples and detailed explanations, suitable for comprehensive reference.
// Bad: sequential const user = await fetchUser() const posts = await fetchPosts()// Good: parallel const [user, posts] = await Promise.all([ fetchUser(), fetchPosts() ])
// Bad: bundles Monaco with main chunk import { MonacoEditor } from './monaco-editor'// Good: loads on demand const MonacoEditor = dynamic( () => import('./monaco-editor').then(m => m.MonacoEditor), { ssr: false } )
// Bad: stale closure risk const addItem = useCallback((item) => { setItems([...items, item]) }, [items]) // recreates on every items change// Good: always uses latest state const addItem = useCallback((item) => { setItems(curr => [...curr, item]) }, []) // stable reference
import { X } from 'lib') — import directly&& for conditional rendering with numbers — use ternary.sort() — use .toSorted()useEffect([]) — use module-level guardNo automatic installation available. Please visit the source repository for installation instructions.
View Installation Instructions1,500+ AI skills, agents & workflows. Install in 30 seconds. Part of the Torly.ai family.
© 2026 Torly.ai. All rights reserved.