AGENT SKILL

react-performance

Reviews and optimizes React component performance and correctness. Covers stale closures, unnecessary re-renders, useEffect cleanup, state design, debounce/throttle, and race conditions. Should be used when the user is concerned about React performance — slow renders, stale closure bugs, or optimizing useMemo/useCallback usage. Distinguished from frontend-code-review which covers general code quality, this skill focuses specifically on React performance and Hook-related issues.

License 许可
MIT
最近更新
2026-04-18
Stars
★ 0
Forks
0

01 前言 Front Matter

name
react-performance
boundary
{ "vs_frontend-code-review": "frontend-code-review covers general code quality, this skill focuses specifically on React performance and Hook-related issues" }
category
coding
description
Reviews and optimizes React component performance and correctness. Covers stale closures, unnecessary re-renders, useEffect cleanup, state design, debounce/throttle, and race conditions. Should be used when the user is concerned about React performance — slow renders, stale closure bugs, or optimizing useMemo/useCallback usage. Distinguished from frontend-code-review which covers general code quality, this skill focuses specifically on React performance and Hook-related issues.

02 资源文件 1

03 SKILL.md 正文

React Performance & Common Pitfalls

Core Capability

Audit React code for performance issues and prevent common runtime pitfalls. The problems this skill catches are subtle — stale closures silently read outdated values, missing cleanup silently leaks memory, and unnecessary re-renders silently degrade performance. They're easy to miss in regular code review but cause real user-facing bugs.

Workflow

  1. Stale closure check — Scan all Hook dependency arrays for missing dependencies
  2. Render analysis — Identify unnecessary re-renders, add memo / useMemo / useCallback
  3. Side effect audit — Confirm all useEffect have corresponding cleanup
  4. State rationality — Check for redundant state or direct state mutation
  5. High-frequency events — Confirm debounce/throttle is correctly applied

1. Stale Closure

The Problem

Closures in function components capture a snapshot of variables at creation time. If dependencies aren't correctly declared, the closure reads stale values — and the bug is silent: no error, just wrong behavior.

Rules

  • useEffect / useCallback / useMemo dependency arrays must declare all external variables
  • State updates that depend on the current value must use functional updates setState(prev => ...)
  • When you need the latest value in a closure without triggering re-renders, use useRef
  • Enable ESLint react-hooks/exhaustive-deps — don't casually // eslint-disable

2. Render Performance

Avoid Unnecessary Re-renders

  • Pure display sub-components should be wrapped in React.memo
  • Object and function props passed to child components should be wrapped in useMemo / useCallback
  • useMemo is for computationally expensive derived data; useCallback is for callbacks passed to children
  • Don't overuse useMemo / useCallback — simple values or functions not passed to children don't need wrapping

List Rendering

  • List key must use stable and unique business identifiers (e.g., id), not array index (unless the list is static and never changes)

3. useEffect Standards

Side Effect Cleanup

  • Event listeners, timers, and subscriptions registered in useEffect must be unregistered in the returned cleanup function
  • Async requests must handle component unmount (AbortController or isMounted flag)
  • Avoid making the useEffect callback itself async — define an async function inside and call it

4. State Management

  • Never directly mutate state objects or arrays — always return new references
  • Data derivable from existing state should not be stored as separate state (use useMemo instead)
  • Multiple related state updates should be merged into a single object or use useReducer

5. High-Frequency Events

  • Search input, window resize, scroll listeners must use debounce or throttle
  • Debounce/throttle function instances must be kept stable via useMemo or useRef — never create them directly in the render function

6. Race Conditions

  • Async requests that depend on external parameters must handle races: when the component unmounts or parameters change, ignore the old request's result

Output Format

## React Performance & Standards Check Report

### 1. Stale Closure Check

- Status: ✅ PASS / ⚠️ WARN / ❌ FAIL
- Issue: [filename/line]: [description] -> [fix suggestion]

### 2. Render Performance

- **Unnecessary re-renders**: [component name] -> [optimization suggestion]
- **List key**: ✅ PASS / ❌ FAIL

### 3. useEffect Side Effects

- **Cleanup function**: ✅ Cleaned / ❌ Missing cleanup -> [specific location]
- **Race handling**: ✅ Handled / ❌ At risk

### 4. State Management

- **Direct mutation**: ✅ PASS / ❌ FAIL -> [specific location]
- **Redundant state**: [derived data suggestion: switch to useMemo]

### 5. High-Frequency Events

- [event name]: ✅ Debounced / ❌ Missing debounce

### Summary

- Score: ? Excellent / ? Good / ? Needs improvement
- [ ] Safe to commit / [ ] Fix before commit

04 同仓库更多 Skills

ImaginerLabs
ImaginerLabs/skill-manager

meeting-minutes

Generate concise, actionable meeting minutes for internal meetings. Includes metadata, attendees, agenda, decisions, action items (owner + due date), and follow-up steps.

行政与办公人员Skill与智能体开发
★ 0
ImaginerLabs
ImaginerLabs/skill-manager

documentation-writer

Diátaxis Documentation Expert. An expert technical writer specializing in creating high-quality software documentation, guided by the principles and structure of the Diátaxis technical documentation authoring framework.

★ 0
ImaginerLabs
ImaginerLabs/skill-manager

doc-coauthoring

Guide users through a structured workflow for co-authoring documentation. Use when user wants to write documentation, proposals, technical specs, decision docs, or similar structured content. This workflow helps users efficiently transfer context, refine content through iteration, and verify the doc works for readers. Trigger when user mentions writing docs, creating proposals, drafting specs, or similar documentation tasks.

内容创作者写作与文案Skill与智能体开发
★ 0
ImaginerLabs
ImaginerLabs/skill-manager

code-review-workflow

Executes comprehensive 4-phase code review: basic review, quality check, bundle analysis, and test coverage. Should be used when the user mentions comprehensive code review, checking code quality, or reviewing staged changes with multi-phase analysis. This is the comprehensive review workflow, distinct from focused skills like frontend-code-review, staged-code-review, or code-change-test-designer.

开发工程师代码审查测试与质量
★ 0
ImaginerLabs
ImaginerLabs/skill-manager

code-change-test-designer

Analyzes code changes and designs comprehensive test cases. Reads diffs, summarizes capability changes, and designs test cases covering main flows and edge cases. Should be used when the user mentions test coverage, designing tests for code changes, or analyzing diff/commit for testing purposes. Distinguished from code-review-workflow which provides comprehensive review, this skill focuses on test case design for code changes.

开发工程师设计师测试与质量视觉设计
★ 0
ImaginerLabs
ImaginerLabs/skill-manager

skill-creator

Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.

Skill与智能体开发
★ 0