react-performance-optimization

react-performance-optimization

React performance optimization patterns using memoization, code splitting, and efficient rendering strategies. Use when optimizing slow React applications, reducing bundle size, or improving user experience with large datasets.

7Star
2Fork
更新于 1/17/2026
SKILL.md
readonly只读
name
react-performance-optimization
description

React performance optimization patterns using memoization, code splitting, and efficient rendering strategies. Use when optimizing slow React applications, reducing bundle size, or improving user experience with large datasets.

React Performance Optimization

Expert guidance for optimizing React application performance through memoization, code splitting, virtualization, and efficient rendering strategies.

When to Use This Skill

  • Optimizing slow-rendering React components
  • Reducing bundle size for faster initial load times
  • Improving responsiveness for large lists or data tables
  • Preventing unnecessary re-renders in complex component trees
  • Optimizing state management to reduce render cascades
  • Improving perceived performance with code splitting
  • Debugging performance issues with React DevTools Profiler

Core Concepts

React Rendering Optimization

React re-renders components when props or state change. Unnecessary re-renders waste CPU cycles and degrade user experience. Key optimization techniques:

  • Memoization: Cache component renders and computed values
  • Code splitting: Load code on demand for faster initial loads
  • Virtualization: Render only visible list items
  • State optimization: Structure state to minimize render cascades

When to Optimize

  1. Profile first: Use React DevTools Profiler to identify actual bottlenecks
  2. Measure impact: Verify optimization improves performance
  3. Avoid premature optimization: Don't optimize fast components

Quick Reference

Load detailed patterns and examples as needed:

Topic Reference File
React.memo, useMemo, useCallback patterns skills/react-performance-optimization/references/memoization.md
Code splitting with lazy/Suspense, bundle optimization skills/react-performance-optimization/references/code-splitting.md
Virtualization for large lists (react-window) skills/react-performance-optimization/references/virtualization.md
State management strategies, context splitting skills/react-performance-optimization/references/state-management.md
useTransition, useDeferredValue (React 18+) skills/react-performance-optimization/references/concurrent-features.md
React DevTools Profiler, performance monitoring skills/react-performance-optimization/references/profiling-debugging.md
Common pitfalls and anti-patterns skills/react-performance-optimization/references/common-pitfalls.md

Optimization Workflow

1. Identify Bottlenecks

# Open React DevTools Profiler
# Record interaction → Analyze flame graph → Find slow components

Look for:

  • Components with yellow/red bars (slow renders)
  • Unnecessary renders (same props/state)
  • Expensive computations on every render

2. Apply Targeted Optimizations

For unnecessary re-renders:

  • Wrap component with React.memo
  • Use useCallback for stable function references
  • Check for inline objects/arrays in props

For expensive computations:

  • Use useMemo to cache results
  • Move calculations outside render when possible

For large lists:

  • Implement virtualization with react-window
  • Ensure proper unique keys (not index)

For slow initial load:

  • Add code splitting with React.lazy
  • Analyze bundle size with webpack-bundle-analyzer
  • Use dynamic imports for heavy dependencies

3. Verify Improvements

# Record new Profiler session
# Compare before/after metrics
# Ensure optimization actually helped

Common Patterns

Memoize Expensive Components

import { memo } from 'react';

const ExpensiveList = memo(({ items, onItemClick }) => {
  return items.map(item => (
    <Item key={item.id} data={item} onClick={onItemClick} />
  ));
});

Cache Computed Values

import { useMemo } from 'react';

function DataTable({ items, filters }) {
  const filteredItems = useMemo(() => {
    return items.filter(item => filters.includes(item.category));
  }, [items, filters]);

  return <Table data={filteredItems} />;
}

Stable Function References

import { useCallback } from 'react';

function Parent() {
  const handleClick = useCallback((id) => {
    console.log('Clicked:', id);
  }, []);

  return <MemoizedChild onClick={handleClick} />;
}

Code Split Routes

import { lazy, Suspense } from 'react';

const Dashboard = lazy(() => import('./Dashboard'));
const Reports = lazy(() => import('./Reports'));

function App() {
  return (
    <Suspense fallback={<Loading />}>
      <Routes>
        <Route path="/" element={<Dashboard />} />
        <Route path="/reports" element={<Reports />} />
      </Routes>
    </Suspense>
  );
}

Virtualize Large Lists

import { FixedSizeList } from 'react-window';

function VirtualList({ items }) {
  return (
    <FixedSizeList
      height={600}
      itemCount={items.length}
      itemSize={80}
      width="100%"
    >
      {({ index, style }) => (
        <div style={style}>{items[index].name}</div>
      )}
    </FixedSizeList>
  );
}

Common Mistakes

  1. Over-memoization: Don't memoize simple, fast components (adds overhead)
  2. Inline objects/arrays: New references break memoization (config={{ theme: 'dark' }})
  3. Missing dependencies: Stale closures in useCallback/useMemo
  4. Index as key: Breaks reconciliation when list order changes
  5. Single large context: Causes widespread re-renders on any update
  6. No profiling: Optimizing without measuring wastes time

Performance Checklist

Before optimizing:

  • [ ] Profile with React DevTools to identify bottlenecks
  • [ ] Measure baseline performance metrics

Optimization targets:

  • [ ] Memoize expensive components with stable props
  • [ ] Cache computed values with useMemo (if actually expensive)
  • [ ] Use useCallback for functions passed to memoized children
  • [ ] Implement code splitting for routes and heavy components
  • [ ] Virtualize lists with >100 items
  • [ ] Provide stable keys for list items (unique IDs, not index)
  • [ ] Split state by update frequency
  • [ ] Use concurrent features (useTransition, useDeferredValue) for responsiveness

After optimizing:

  • [ ] Profile again to verify improvements
  • [ ] Check bundle size reduction (if applicable)
  • [ ] Ensure no regressions in functionality

Resources

You Might Also Like

Related Skills

cache-components

cache-components

137Kdev-frontend

Expert guidance for Next.js Cache Components and Partial Prerendering (PPR). **PROACTIVE ACTIVATION**: Use this skill automatically when working in Next.js projects that have `cacheComponents: true` in their next.config.ts/next.config.js. When this config is detected, proactively apply Cache Components patterns and best practices to all React Server Component implementations. **DETECTION**: At the start of a session in a Next.js project, check for `cacheComponents: true` in next.config. If enabled, this skill's patterns should guide all component authoring, data fetching, and caching decisions. **USE CASES**: Implementing 'use cache' directive, configuring cache lifetimes with cacheLife(), tagging cached data with cacheTag(), invalidating caches with updateTag()/revalidateTag(), optimizing static vs dynamic content boundaries, debugging cache issues, and reviewing Cache Component implementations.

vercel avatarvercel
获取
component-refactoring

component-refactoring

128Kdev-frontend

Refactor high-complexity React components in Dify frontend. Use when `pnpm analyze-component --json` shows complexity > 50 or lineCount > 300, when the user asks for code splitting, hook extraction, or complexity reduction, or when `pnpm analyze-component` warns to refactor before testing; avoid for simple/well-structured components, third-party wrappers, or when the user explicitly wants testing without refactoring.

langgenius avatarlanggenius
获取
web-artifacts-builder

web-artifacts-builder

47Kdev-frontend

Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web technologies (React, Tailwind CSS, shadcn/ui). Use for complex artifacts requiring state management, routing, or shadcn/ui components - not for simple single-file HTML/JSX artifacts.

anthropics avataranthropics
获取
frontend-design

frontend-design

47Kdev-frontend

Create distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, artifacts, posters, or applications (examples include websites, landing pages, dashboards, React components, HTML/CSS layouts, or when styling/beautifying any web UI). Generates creative, polished code and UI design that avoids generic AI aesthetics.

anthropics avataranthropics
获取
react-modernization

react-modernization

28Kdev-frontend

Upgrade React applications to latest versions, migrate from class components to hooks, and adopt concurrent features. Use when modernizing React codebases, migrating to React Hooks, or upgrading to latest React versions.

wshobson avatarwshobson
获取
tailwind-design-system

tailwind-design-system

28Kdev-frontend

Build scalable design systems with Tailwind CSS v4, design tokens, component libraries, and responsive patterns. Use when creating component libraries, implementing design systems, or standardizing UI patterns.

wshobson avatarwshobson
获取