React best practices
Skill ComeOnOliver/skillshub/skills/aiskillstore/marketplace/vercel-labs/react-best-practices
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.From its SKILL.md
npx -y skills add ComeOnOliver/skillshub --skill react-best-practicesAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
3.5 KB, 723 tokens by cl100k_base, as published. Nobody here has run it
React Best Practices
Overview
Comprehensive performance optimization guide for React and Next.js applications, containing 40+ rules across 8 categories. Rules are prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new React components or Next.js pages
- Implementing data fetching (client or server-side)
- Reviewing code for performance issues
- Refactoring existing React/Next.js code
- Optimizing bundle size or load times
Priority-Ordered Guidelines
Rules are prioritized by impact:
| Priority | Category | Impact |
|---|---|---|
| 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 |
Quick Reference
Critical Patterns (Apply First)
Eliminate Waterfalls:
- Defer await until needed (move into branches)
- Use
Promise.all()for independent async operations - Start promises early, await late
- Use
better-allfor partial dependencies - Use Suspense boundaries to stream content
Reduce Bundle Size:
- Avoid barrel file imports (import directly from source)
- Use
next/dynamicfor heavy components - Defer non-critical third-party libraries
- Preload based on user intent
High-Impact Server Patterns
- Use
React.cache()for per-request deduplication - Use LRU cache for cross-request caching
- Minimize serialization at RSC boundaries
- Parallelize data fetching with component composition
Medium-Impact Client Patterns
- Use SWR for automatic request deduplication
- Defer state reads to usage point
- Use lazy state initialization for expensive values
- Use derived state subscriptions
- Apply
startTransitionfor non-urgent updates
Rendering Patterns
- Animate SVG wrappers, not SVG elements directly
- Use
content-visibility: autofor long lists - Prevent hydration mismatch with inline scripts
- Use explicit conditional rendering (
? :not&&)
JavaScript Patterns
- Batch DOM CSS changes via classes
- Build index maps for repeated lookups
- Cache repeated function calls
- Use
toSorted()instead ofsort()for immutability - Early length check for array comparisons
References
Full documentation with code examples is available in:
references/react-performance-guidelines.md- Complete guide with all patternsreferences/rules/- Individual rule files organized by category
To look up a specific pattern, grep the rules directory:
grep -l "suspense" references/rules/
grep -l "barrel" references/rules/
grep -l "swr" references/rules/
Rule Categories in references/rules/
async-*- Waterfall elimination patternsbundle-*- Bundle size optimizationserver-*- Server-side performanceclient-*- Client-side data fetchingrerender-*- Re-render optimizationrendering-*- DOM rendering performancejs-*- JavaScript micro-optimizationsadvanced-*- Advanced patterns
What ships with it
303.6 KB alongside SKILL.md
GitHub clipped this repository’s file list, so this is at least 47 files and may be more.
references/
- react-performance-guidelines.md47.6 KB
- rules/advanced-event-handler-refs.md960 B
- rules/advanced-use-latest.md1.2 KB
- rules/async-api-routes.md1.1 KB
- rules/async-defer-await.md2.0 KB
- rules/async-dependencies.md942 B
- rules/async-parallel.md654 B
- rules/async-suspense-boundaries.md1.6 KB
- rules/bundle-barrel-imports.md2.3 KB
- rules/bundle-conditional.md870 B
- rules/bundle-defer-third-party.md922 B
- rules/bundle-dynamic-imports.md791 B
- rules/bundle-preload.md1.1 KB
- rules/client-event-listeners.md1.9 KB
- rules/client-swr-dedup.md1.1 KB
- rules/js-batch-dom-css.md1.9 KB
- rules/js-cache-function-results.md1.9 KB
- rules/js-cache-property-access.md532 B
- rules/js-cache-storage.md1.6 KB
- rules/js-combine-iterations.md753 B
- rules/js-early-exit.md1.1 KB
- rules/js-hoist-regexp.md994 B
- rules/js-index-maps.md837 B
- rules/js-length-check-first.md1.7 KB
- rules/js-min-max-loop.md2.1 KB
- rules/js-set-map-lookups.md532 B
- rules/js-tosorted-immutable.md1.7 KB
- rules/rendering-activity.md564 B
- rules/rendering-animate-svg-wrapper.md1.2 KB
- rules/rendering-conditional-render.md983 B
- rules/rendering-content-visibility.md822 B
- rules/rendering-hoist-jsx.md819 B
- rules/rendering-hydration-no-flicker.md2.3 KB
- rules/rendering-svg-precision.md591 B
- rules/rerender-defer-reads.md973 B
- rules/rerender-dependencies.md827 B
- rules/rerender-derived-state.md724 B
- rules/rerender-lazy-state-init.md2.0 KB
- rules/rerender-memo.md935 B
- rules/rerender-transitions.md1.0 KB
7 more files not listed here. See all 47 in the repository.
Gives 2 of the 12 instructions most performance cost skills give in 723 tokens
Counted across 797 of the 1,117 authors here whose files we hold, read 2026-09-06
- Check for product marketing context firstin 46 of 797, across 20 files
- Measure before optimizingin 31 of 797, across 25 files
- Profile first to identify the actual bottleneckin 23 of 797, across 22 files
- Verify your robots.txt allows AI crawlersin 21 of 797, across 12 files
- Import directly and avoid barrel fileshere, and in 19 of 797, across 15 files
- Spawn all runs in the same turnin 18 of 797, across 11 files
- Write a draft of the skillin 17 of 797, across 10 files
- Understand the user's intentin 17 of 797, across 10 files
- Use React.cache for per-request deduplicationhere, and in 16 of 797, across 11 files
- Profile before optimizingin 16 of 797, across 14 files
- Include specific numbers with sourcesin 15 of 797, across 8 files
- Add lazy loading to below-fold imagesin 15 of 797, across 10 files
Said here and by no other author read
- Defer await until needed
- Batch DOM CSS changes via classes
Grouped from the skills themselves: near-identical wordings counted once, and counted by distinct author, so one author publishing three of these counts once. Length counted with cl100k_base; the agent that loads this file may tokenize it differently.