Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)33k · #9107

react-best-practices

Skill này làm gì

Skill này hướng dẫn agent AI rà soát và cải thiện tốc độ của các ứng dụng React và Next.js. Skill dành cho lập trình viên front-end muốn trang tải nhanh hơn và giao diện mượt hơn.

Khi nào nên dùng

  • ✓Khi ứng dụng React hoặc Next.js của bạn tải chậm và bạn muốn tìm nguyên nhân.
  • ✓Khi bạn rà soát các component và muốn giảm số lần render lại không cần thiết.
  • ✓Khi bạn muốn giảm lượng JavaScript gửi đến trình duyệt.

Liên kết skill

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/web-development/react-best-practices/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/web-development/react-best-practices/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Trang Next.js của tôi tải chậm. Bạn có thể rà soát và gợi ý các cải thiện hiệu năng lớn nhất không?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Agent đối chiếu mã với các quy tắc của skill, bắt đầu với những quy tắc có tác động lớn nhất như loại bỏ chuỗi yêu cầu nối tiếp và giảm kích thước gói.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

React Best Practices - Performance Optimization

Comprehensive performance optimization guide for React and Next.js applications with 40+ rules organized by impact level. Designed to help developers eliminate performance bottlenecks and follow best practices.

When to use this skill

Use React Best Practices when:

  • Optimizing React or Next.js application performance
  • Reviewing code for performance improvements
  • Refactoring existing components for better performance
  • Implementing new features with performance in mind
  • Debugging slow rendering or loading issues
  • Reducing bundle size
  • Eliminating request waterfalls

Key areas covered:

  • Eliminating Waterfalls (CRITICAL): Prevent sequential async operations
  • Bundle Size Optimization (CRITICAL): Reduce initial JavaScript payload
  • Server-Side Performance (HIGH): Optimize RSC and data fetching
  • Client-Side Data Fetching (MEDIUM-HIGH): Implement efficient caching
  • Re-render Optimization (MEDIUM): Minimize unnecessary re-renders
  • Rendering Performance (MEDIUM): Optimize browser rendering
  • JavaScript Performance (LOW-MEDIUM): Micro-optimizations for hot paths
  • Advanced Patterns (LOW): Specialized techniques for edge cases

Quick reference

Critical priorities

  1. Defer await until needed - Move awaits into branches where they're used
  2. Use Promise.all() - Parallelize independent async operations
  3. Avoid barrel imports - Import directly from source files
  4. Dynamic imports - Lazy-load heavy components
  5. Strategic Suspense - Stream content while showing layout

Common patterns

Parallel data fetching:

const [user, posts, comments] = await Promise.all([
  fetchUser(),
  fetchPosts(),
  fetchComments()
])

Direct imports:

// ❌ Loads entire library
import { Check } from 'lucide-react'

// ✅ Loads only what you need
import Check from 'lucide-react/dist/esm/icons/check'

Dynamic components:

import dynamic from 'next/dynamic'

const MonacoEditor = dynamic(
  () => import('./monaco-editor'),
  { ssr: false }
)

Using the guidelines

The complete performance guidelines are available in the references folder:

  • react-performance-guidelines.md: Complete guide with all 40+ rules, code examples, and impact analysis

Each rule includes:

  • Incorrect/correct code comparisons
  • Specific impact metrics
  • When to apply the optimization
  • Real-world examples

Categories overview

1. Eliminating Waterfalls (CRITICAL)

Waterfalls are the #1 performance killer. Each sequential await adds full network latency.

  • Defer await until needed
  • Dependency-based parallelization
  • Prevent waterfall chains in API routes
  • Promise.all() for independent operations
  • Strategic Suspense boundaries

2. Bundle Size Optimization (CRITICAL)

Reducing initial bundle size improves Time to Interactive and Largest Contentful Paint.

  • Avoid barrel file imports
  • Conditional module loading
  • Defer non-critical third-party libraries
  • Dynamic imports for heavy components
  • Preload based on user intent

3. Server-Side Performance (HIGH)

Optimize server-side rendering and data fetching.

  • Cross-request LRU caching
  • Minimize serialization at RSC boundaries
  • Parallel data fetching with component composition
  • Per-request deduplication with React.cache()

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

Automatic deduplication and efficient data fetching patterns.

  • Deduplicate global event listeners
  • Use SWR for automatic deduplication

5. Re-render Optimization (MEDIUM)

Reduce unnecessary re-renders to minimize wasted computation.

  • Defer state reads to usage point
  • Extract to memoized components
  • Narrow effect dependencies
  • Subscribe to derived state
  • Use lazy state initialization
  • Use transitions for non-urgent updates

6. Rendering Performance (MEDIUM)

Optimize the browser rendering process.

  • Animate SVG wrapper instead of SVG element
  • CSS content-visibility for long lists
  • Hoist static JSX elements
  • Optimize SVG precision
  • Prevent hydration mismatch without flickering
  • Use Activity component for show/hide
  • Use explicit conditional rendering

7. JavaScript Performance (LOW-MEDIUM)

Micro-optimizations for hot paths.

  • Batch DOM CSS changes
  • Build index maps for repeated lookups
  • Cache property access in loops
  • Cache repeated function calls
  • Cache storage API calls
  • Combine multiple array iterations
  • Early length check for array comp
Câu hỏi thường gặp

Waterfall trong ngữ cảnh này là gì?

Đó là khi các yêu cầu dữ liệu chạy lần lượt thay vì song song, khiến trang chậm.

Skill có bao gồm Next.js không?

Có. Skill bao gồm hiệu năng của cả React và Next.js, kể cả server-side rendering.

Các quy tắc được sắp xếp thế nào?

Chúng được nhóm theo mức tác động, từ nghiêm trọng đến thấp, để bạn sửa các vấn đề lớn nhất trước.

Chi tiết

Mô tả gốc của tác giả

Comprehensive React and Next.js performance optimization guide with 40+ rules for eliminating waterfalls, optimizing bundles, and improving rendering. Use when optimizing React apps, reviewing performance, or refactoring components.

repo: davila7/claude-code-templates

Độ phổ biến

Sao GitHub
33k
Vị trí xếp hạng
#9107
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự