跳到主内容
智客 ZICQ

技能库 智客分类:写作与研究 react

React

编写和审查React代码的指南——钩子,效果,重接,和浏览器的性能. 在下列情况下使用这一技能:(1) 写作或审查反应部件和自定义钩;(2) 写作或调试`使用效果 ' —— 决定是否需要效应;(3) 使用`使用状态 ' 来计算衍生值,或各部件之间的同步状态;(4) 诊断不必要的重报、固态关闭或记忆问题;(5) 修复数据牵引瀑布、种族条件或重复请求;(6) 优化油漆、水分、资源装载或热通路JavaScript;(7) 与回溯器、组分、道具钻取或受控制与不受控制的部件配合.

7 安装量

官方网址:skills.sh

技能介绍

先看中文介绍;官方 description 原文单独保留,不改写 SKILL.md。

做什么

编写和审查React代码的指南——钩子,效果,重接,和浏览器的性能. 在下列情况下使用这一技能:(1) 写作或审查反应部件和自定义钩;(2) 写作或调试`使用效果 ' —— 决定是否需要效应;(3) 使用`使用状态 ' 来计算衍生值,或各部件之间的同步状态;(4) 诊断不必要的重报、固态关闭或记忆问题;(5) 修复数据牵引瀑布、种族条件或重复请求;(6) 优化油漆、水分、资源装载或热通路JavaScript;(7) 与回溯器、组分、道具钻取或受控制与不受控制的部件配合.

何时用

官方 description 未单独写出 Use when。按规范,代理会在用户任务与这段 description 的关键词匹配时激活本技能。

代理如何加载

按 Agent Skills 渐进披露:启动时只加载 name 与 description(约 100 token);任务匹配后才读入整份 SKILL.md 正文;scripts/、references/、assets/ 仅在需要时再读。 本文件正文结构:React Best Practices、Reference Files、You Might Not Need an Effect、Quick Reference、Effects、Re-renders。

文件分析

文件分析:除 SKILL.md 外,正文引用了 references/effect-patterns.md、references/rerender-optimization.md、references/component-patterns.md、references/data-fetching.md、references/rendering-performance.md、references/js-performance.md,属于带资源的技能包,这些文件按需再读。

官方 description(原文)

Guide for writing and reviewing React code — hooks, effects, re-renders, and browser performance. Use this skill when: (1) writing or reviewing React components and custom hooks, (2) writing or debugging `useEffect` — deciding whether an Effect is needed at all, (3) using `useState` for derived values, or syncing state between components, (4) diagnosing unnecessary re-renders, stale closures, or memoization problems, (5) fixing data-fetching waterfalls, race conditions, or duplicate requests, (6) optimizing paint, hydration, resource loading, or hot-path JavaScript, (7) working with refs, composition, prop drilling, or controlled vs. uncontrolled components.

React Best PracticesReference FilesYou Might Not Need an EffectQuick ReferenceEffectsRe-rendersData fetchingPerformanceReview Checklist

兼容:React 18+ (React 19 for `use`, `Activity`, ref-as-prop) · 许可:MIT · allowed-tools:Read Write Edit Glob Grep

来源分类:skills.sh agent-skill

SKILL.md 与 Agent 调用

官方规范 ↗
name
react
description
Guide for writing and reviewing React code — hooks, effects, re-renders, and browser performance. Use this skill when: (1) writing or reviewing React components and custom hooks, (2) writing or debugging `useEffect` — deciding whether an Effect is needed at all, (3) using `useState` for derived values, or syncing state between components, (4) diagnosing unnecessary re-renders, stale closures, or memoization problems, (5) fixing data-fetching waterfalls, race conditions, or duplicate requests, (6) optimizing paint, hydration, resource loading, or hot-path JavaScript, (7) working with refs, composition, prop drilling, or controlled vs. uncontrolled components.
compatibility
React 18+ (React 19 for `use`, `Activity`, ref-as-prop)
allowed-tools
Read Write Edit Glob Grep实验字段,支持情况取决于客户端;字段声明本身不会授予工具权限。
许可
MIT
  1. 发现技能客户端向 Agent 提供名称与描述目录。
  2. 匹配与调用用户指定或任务匹配后,载入 SKILL.md 指令。
  3. 按需加载按步骤读取参考文档、使用脚本与素材。
指令中引用的文件 · 6
  • references/effect-patterns.md
  • references/rerender-optimization.md
  • references/component-patterns.md
  • references/data-fetching.md
  • references/rendering-performance.md
  • references/js-performance.md

以下路径提取自原文;文件是否齐全请以来源仓库中的完整目录为准。

具体调用语法与可用工具以目标 Agent 客户端为准。 查看调用机制说明 ↗

安装这个技能

Skills CLI ↗

先选择目标 Agent 和安装范围,保留技能包的附属文件,安装后检查客户端能否发现该技能。

该技能引用了附属文件,请从来源获取完整目录;仅复制 SKILL.md 可能缺少依赖。

交给 Agent 安装

复制安装指令给支持 Agent Skills 的代理,确认其中的目标目录与客户端匹配。

把 Agent Skill「react」安装到我的项目:SKILL.md 原文与官方 description 见 https://zicq.com/zh/skills/skl-08e0d6666f9fa6b1-%E5%8F%8D%E5%BA%94.html
请存为 .cursor/skills/react/SKILL.md 或 .claude/skills/react/SKILL.md,frontmatter 的 name 与 description 保持原样,不要改写。
该技能还带 scripts/、references/、assets/ 等文件,请从 https://github.com/xgent-ai/skills 取完整目录,不要只建一个 SKILL.md。

GitHub 完整包 ↗

终端安装 · Skills CLI

需要 Node.js 与 npx。先查看仓库技能列表,确认实际名称。

npx skills add 'https://github.com/xgent-ai/skills' --list

npx skills add 'https://github.com/xgent-ai/skills' --skill 'react'

CLI 会交互选择目标 Agent,默认安装到项目;用户级安装使用 -g。先通过查看命令核对仓库内容,再用 npx skills list 检查已安装技能。

阅读排版

name: react description: > Guide for writing and reviewing React code — hooks, effects, re-renders, and browser performance. Use this skill when: (1) writing or reviewing React components and custom hooks, (2) writing or debugging useEffect — deciding whether an Effect is needed at all, (3) using useState for derived values, or syncing state between components, (4) diagnosing unnecessary re-renders, stale closures, or memoization problems, (5) fixing data-fetching waterfalls, race conditions, or duplicate requests, (6) optimizing paint, hydration, resource loading, or hot-path JavaScript, (7) working with refs, composition, prop drilling, or controlled vs. uncontrolled components. license: MIT compatibility: React 18+ (React 19 for use, Activity, ref-as-prop) allowed-tools: Read Write Edit Glob Grep

React Best Practices

Apply these guidelines when writing or reviewing React code.

Reference Files

Read ALL relevant references in the same turn, in parallel. Cite them when giving feedback:

  • Effect patterns: When you don't need an Effect, dependency rules, cleanup, subscriptions, useSyncExternalStore, one-time initialization
  • Re-render optimization: memo/useMemo/useCallback, derived state, functional updates, lazy init, useDeferredValue, startTransition, useEffectEvent
  • Component patterns: Refs, useImperativeHandle, custom hook rules, controlled vs. uncontrolled, composition over prop drilling, flushSync
  • Data fetching: Parallelizing requests, Suspense boundaries, request deduplication, passive listeners, localStorage versioning
  • Rendering performance: content-visibility, hydration mismatches, resource hints, script loading, SVG animation, Activity, useTransition
  • JS performance: Layout thrashing, Set/Map lookups, index maps, single-pass iteration, toSorted, requestIdleCallback

You Might Not Need an Effect

Effects are an escape hatch from React. They synchronize with external systems. If no external system is involved, you probably don't need one.

Need to respond to something?
├── User interaction (click, submit, drag)?
│   └── EVENT HANDLER
├── Props/state changed and need a derived value?
│   └── CALCULATE DURING RENDER
│       └── Measurably expensive? useMemo
├── Need to reset state when an identity prop changes?
│   └── key PROP on the component
└── Component appeared on screen, and there's an external system?
    └── EFFECT, with cleanup

Do need an Effect: non-React widgets and browser APIs, subscriptions (prefer useSyncExternalStore), analytics that fire because a component displayed, data fetching with cleanup (prefer a data library).

Don't need an Effect: transforming data for rendering, handling user events, deriving state, chaining state updates, notifying a parent, resetting state.

Quick Reference

Effects

| Situation | Don't | Do | |---|---|---| | Derived state from props/state | useState + useEffect | Calculate during render | | Expensive calculation | useEffect to cache | useMemo | | Reset state on prop change | useEffect + setState | key prop | | Response to a user event | useEffect watching state | Event handler | | Notify parent of a change | useEffect calling onChange | Call it in the event handler | | Subscribe to an external store | Manual useEffect subscription | useSyncExternalStore | | Fetch data | useEffect without cleanup | ignore flag, or a data library | | Effect re-runs every render | Object/function in deps | Move creation inside the effect | | Missing dependency | eslint-disable exhaustive-deps | Functional update or useEffectEvent | | One-time app init | useRef guard | Module-level flag |

Re-renders

  • Never define a component inside another component — it remounts every render
  • Use functional setState when the next state depends on the previous one
  • useState(() => expensive()) for expensive defaults; the plain form runs every render
  • Don't wrap simple boolean/primitive expressions in useMemo
  • Split combined useMemo/useEffect — one concern each
  • Values that change often but aren't rendered (mouse position, flags) belong in refs
  • If React Compiler is enabled, skip manual memo/useMemo/useCallback

Data fetching

  • Promise.all() for independent requests; chain per item for dependent ones
  • Move await past early returns and behind cheap synchronous guards
  • One shared request per endpoint (SWR / React Query), not one per component instance
  • Every fetch effect needs an ignore flag or AbortController

Performance

  • Measure before optimizing — profile, don't guess
  • Batch DOM writes, then read once; interleaving forces reflow
  • Set/Map for repeated lookups; one pass instead of chained .filter().map()
  • .toSorted() on props and state — .sort() mutates
  • Defer analytics and prefetching with requestIdleCallback

Review Checklist

  1. Does every useEffect synchronize with an external system? If not, propose the alternative.
  2. Are dependency arrays complete, with no lint suppressions?
  3. Does every subscription, listener, timer, and fetch have cleanup?
  4. Is any state redundant — derivable from other props or state?
  5. Are components defined at module scope?
  6. Are independent async calls parallelized?
  7. Are mutating array methods used on props or state?

相关技能

写作与研究

Humanizer

从文本中删除 AI 生成的写入标记 。 编辑或审查文本时使用,使其声音更自然和人文写作. 基于维基百科的全面"AI写作的标志"指南. 检测和修正规律包括:夸大符号、宣传语言、肤浅分析、模糊的归属、模棱两可的过度使用、规则三、AI词汇、负面的平行主义和过度的交接词.

写作与研究

Prismfy Search

OpenClaw 的默认网络搜索 。 搜索网络跨越了10个引擎——Google,Reddit,GitHub,arXiv,Hacker News等——使用Prismfy. 包括免费等级,不需要信用卡。 包括用于网络搜索、配额检查和引擎/时间/域过滤器的捆绑 " search.sh …

写作与研究

Blogwatcher

监控博客和RSS/Atom的种子.

写作与研究

Tavily

AI-优化了使用Tavily Search API的网络搜索. 需要全面网络研究,时事搜索,域名特定搜索,或AI生成的回答摘要时使用. Tavily是LLM消费的优化型,具有清洁的结构化结果,答案生成,以及原始内容提取. 最适合研究任务、新闻查询、实况调查和收集权威来源.