react-best-practices

Applies 45 performance optimization rules to React and Next.js code.

1|Updated Aug 4, 2026
One-click install
npx skills add https://github.com/Hamzaoui-Louai/LEAN-gym-dashboard-frontend --skill react-best-practices-hamzaoui-louai
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react-best-practices
Source: https://github.com/Hamzaoui-Louai/LEAN-gym-dashboard-frontend/tree/main/.opencode/skills/react-best-practices
Command: npx skills add https://github.com/Hamzaoui-Louai/LEAN-gym-dashboard-frontend --skill react-best-practices-hamzaoui-louai

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? React and Next.js applications often suffer from slow load times, data-fetching waterfalls, bloated bundles, and unnecessary re-renders. This Skill provides a structured, impact-prioritized rule set so AI agents and developers can systematically identify and fix performance issues during code generation, refactoring, and review. ## Core Features & Use Cases - 45 Prioritized Rules Across 8 Categories: Covers eliminating waterfalls, bundle size optimization, server-side performance, client-side data fetching, re-render optimization, rendering performance, JavaScript micro-optimizations, and advanced patterns. - Incorrect vs. Correct Code Examples: Every rule includes concrete TypeScript/TSX examples showing the anti-pattern and the optimized implementation, with impact metrics like "2-10x improvement" or "200-800ms import cost". - Use Case: When writing a new Next.js page that fetches user data, config, and posts, apply the waterfall rules to parallelize independent fetches with Promise.all(), use React.cache() for per-request deduplication, and wrap slow sections in Suspense boundaries for faster initial paint. ## Quick Start Review my React component for performance issues and apply the relevant optimization rules from the react-best-practices guide.

Frequently Asked Questions about react-best-practices

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I eliminate data fetching waterfalls in Next.js?

Execute independent async operations concurrently with Promise.all() instead of sequential awaits, and start promises early in API routes before awaiting them. For partial dependencies, use the better-all library to maximize parallelism automatically.

How to reduce bundle size in React applications?

Import directly from source files instead of barrel files like 'lucide-react' or '@mui/material', which can load thousands of unused modules. Use next/dynamic for heavy components and defer non-critical third-party libraries until after hydration.

What is the difference between React.cache() and LRU caching?

React.cache() deduplicates requests within a single server request only, while an LRU cache persists data across sequential requests. Use React.cache() for per-request deduplication and lru-cache for cross-request caching in serverless environments.

Does this guide work with the React Compiler enabled?

Yes, but some manual optimizations become unnecessary. With React Compiler enabled, manual memoization with memo() and useMemo(), plus static JSX hoisting, are handled automatically by the compiler.

When should I not use Suspense boundaries for data fetching?

Avoid Suspense when data is critical for layout decisions, needed for SEO content above the fold, or when queries are small and fast. Also skip it when you want to prevent layout shift from loading-to-content jumps.

Why does my React app re-render too often?

Common causes include subscribing to continuous values instead of derived booleans, using object dependencies in useEffect instead of primitives, and reading state in components that only need it inside callbacks. Narrow effect dependencies and defer state reads to the usage point.