← Back to Skills

react-best-practices

active

Analyzes React and Vite code (.tsx, .jsx, .ts, .js) to identify performance issues, applies 40+ optimization rules across 7 prioritized categories (waterfalls, bundle size, data fetching, re-renders, rendering, JavaScript, advanced patterns), and refactors code following TanStack Query best practices. Use when optimizing React components, reducing bundle size, eliminating async waterfalls, fixing re-render issues, or implementing efficient data fetching patterns. Do NOT use for backend/server-side optimization or non-React frameworks like Vue or Angular.

Owner: vercel Category: workflow-automation Version: 1.0.0 Tokens: ~32k
reactviteperformanceoptimizationtanstack-query
96

Quality Score Breakdown

Structure (15%) 18/18
Show checks (11)
  • SKILL.md exists with exact casing 3/3
  • Valid YAML frontmatter 3/3
  • No unexpected frontmatter keys 1/1
  • Name field valid (kebab-case) 2/2
  • Name matches folder name 1/1
  • Description field present 2/2
  • No angle brackets in frontmatter 1/1
  • Folder name is kebab-case 1/1
  • No README.md inside skill folder 1/1
  • Test directory with test-cases.yml exists 2/2
  • Status 'active' is valid 1/1
Description (20%) 20/22
Show checks (7)
  • Contains action verbs: analyzes 2/4
  • Contains trigger indicators: use when, use for 5/5
  • Description is specific and actionable 4/4
  • File types mentioned in description 3/3
  • Description length: 560/1024 chars 2/2
  • Has negative triggers (scope boundaries) 2/2
  • Owner/author specified in metadata 2/2
Instructions (25%) 27/28
Show checks (8)
  • Skill body has content 3/3
  • Has step/section structure 4/4
  • Includes examples 5/5
  • Includes error handling 4/4
  • Uses progressive disclosure (references/scripts) 4/4
  • Instructions could be more actionable — use 'Run X', 'Call Y', 'Check Z' 2/3
  • Word count: 622/5000 2/2
  • All referenced paths exist 3/3
Test Coverage (25%) 29/29
Show checks (10)
  • test-cases.yml exists and parses 3/3
  • 7 should-trigger tests ✓ 4/4
  • 4 should-not-trigger tests ✓ 3/3
  • 7 functional tests ✓ 5/5
  • 2 negative tests ✓ 3/3
  • 3 edge case tests ✓ 3/3
  • Performance baseline documented 2/2
  • All functional tests have ≥2 assertions 2/2
  • All trigger phrases are diverse 2/2
  • All assertions are specific 2/2
Security (15%) 14/15
Show checks (5)
  • No secrets detected 5/5
  • No injection vectors in frontmatter 3/3
  • Name is not reserved 3/3
  • No suspicious code patterns 2/2
  • 22 external URLs found — verify they're necessary: https://vercel.com/blog/how-we-optimized-package-imports-in-next-js](https://ver, https://tanstack.com/query](https://tanstack.com/query, https://react.dev/learn/react-compiler 1/2

Test Coverage

7
Should Trigger
4
Should Not Trigger
7
Functional
2
Negative
3
Edge Cases
Yes
LLM Evals

React Best Practices

Comprehensive performance optimization guide for React and Vite applications, with TanStack Query for data fetching. Contains 40+ rules across 7 categories, prioritized by impact to guide automated refactoring and code generation.

When to Apply

Check these guidelines when:

  • Creating new React components
  • Implementing data fetching with TanStack Query
  • Reviewing code for performance issues
  • Refactoring existing React code
  • Optimizing bundle size or load times

Rule Categories by Priority

PriorityCategoryImpactPrefix
1Eliminating WaterfallsCRITICALasync-
2Bundle Size OptimizationCRITICALbundle-
3Client-Side Data FetchingMEDIUM-HIGHclient-
4Re-render OptimizationMEDIUMrerender-
5Rendering PerformanceMEDIUMrendering-
6JavaScript PerformanceLOW-MEDIUMjs-
7Advanced PatternsLOWadvanced-

Quick Reference

1. Eliminating Waterfalls (CRITICAL)

  • async-defer-await - Move await into branches where actually used
  • async-parallel - Use Promise.all() for independent operations
  • async-dependencies - Use better-all for partial dependencies
  • async-api-routes - Start promises early, await late in API routes
  • async-suspense-boundaries - Use Suspense to stream content

2. Bundle Size Optimization (CRITICAL)

  • bundle-barrel-imports - Import directly, avoid barrel files
  • bundle-dynamic-imports - Use React.lazy for heavy components
  • bundle-defer-third-party - Load analytics/logging after initial render
  • bundle-conditional - Load modules only when feature is activated
  • bundle-preload - Preload on hover/focus for perceived speed

3. Client-Side Data Fetching (MEDIUM-HIGH)

  • client-swr-dedup - Use TanStack Query for automatic request deduplication
  • client-cache-lru - Use LRU cache for cross-component caching
  • client-event-listeners - Deduplicate global event listeners

4. Re-render Optimization (MEDIUM)

  • rerender-defer-reads - Don’t subscribe to state only used in callbacks
  • rerender-memo - Extract expensive work into memoized components
  • rerender-dependencies - Use primitive dependencies in effects
  • rerender-derived-state - Subscribe to derived booleans, not raw values
  • rerender-functional-setstate - Use functional setState for stable callbacks
  • rerender-lazy-state-init - Pass function to useState for expensive values
  • rerender-transitions - Use startTransition for non-urgent updates

5. Rendering Performance (MEDIUM)

  • rendering-animate-svg-wrapper - Animate div wrapper, not SVG element
  • rendering-content-visibility - Use content-visibility for long lists
  • rendering-hoist-jsx - Extract static JSX outside components
  • rendering-svg-precision - Reduce SVG coordinate precision
  • rendering-hydration-no-flicker - Use inline script for client-only data
  • rendering-activity - Use Activity component for show/hide
  • rendering-conditional-render - Use ternary, not && for conditionals

6. JavaScript Performance (LOW-MEDIUM)

  • js-batch-dom-css - Group CSS changes via classes or cssText
  • js-index-maps - Build Map for repeated lookups
  • js-cache-property-access - Cache object properties in loops
  • js-cache-function-results - Cache function results in module-level Map
  • js-cache-storage - Cache localStorage/sessionStorage reads
  • js-combine-iterations - Combine multiple filter/map into one loop
  • js-length-check-first - Check array length before expensive comparison
  • js-early-exit - Return early from functions
  • js-hoist-regexp - Hoist RegExp creation outside loops
  • js-min-max-loop - Use loop for min/max instead of sort
  • js-set-map-lookups - Use Set/Map for O(1) lookups
  • js-tosorted-immutable - Use toSorted() for immutability

7. Advanced Patterns (LOW)

  • advanced-event-handler-refs - Store event handlers in refs
  • advanced-use-latest - useLatest for stable callback refs

How to Use

Consult individual rule files for detailed explanations and code examples. Verify your implementation against each rule’s correct and incorrect patterns:

rules/async-parallel.md
rules/bundle-barrel-imports.md
rules/_sections.md

Each rule file contains:

  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • Additional context and references

Full Compiled Document

For the complete guide with all rules expanded: AGENTS.md