AGENT SKILL

react-review

Use when reviewing React components, hooks, or route files for idiomatic React, when the user asks for refactor targets or a React cleanup pass, or types /react-review. Reports composition, colocation, state ownership, and repo-idiom findings ranked by hurt. It reports, it does not fix. External scanner counterpart is react-doctor.

License 许可
AGPL-3.0
所属仓库
krake747/next-bite
最近更新
2026-11-15
Stars
★ 0
Forks
1

01 前言 Front Matter

name
react-review
version
1.0.0
description
Use when reviewing React components, hooks, or route files for idiomatic React, when the user asks for refactor targets or a React cleanup pass, or types /react-review. Reports composition, colocation, state ownership, and repo-idiom findings ranked by hurt. It reports, it does not fix. External scanner counterpart is react-doctor.

02 资源文件 2

03 SKILL.md 正文

React Review

A specialized review skill. It does one thing: judge React code against this repo's idioms and report what to refactor, ranked by how much it hurts. It does not build features or fix the code. Point it at a diff, a component, a hook, or a file.

This skill owns structure: composition, colocation, ownership, and idiom. When a finding is visual (spacing, motion, contrast), leave it for a UI review pass. When a finding is a known diagnostic with a scanner recipe, defer to react-doctor.

Operating posture

Review like the engineer who will maintain the file. Code that renders but resists change, hides its data flow, or duplicates what the framework owns is a regression, not a pass. Default to flagging. Approval is earned, not assumed.

Behavior first

Start from the user-observable behavior, not the code shape. No behavior change means no finding above a nit. Judge data shapes from the caller's side: the reader decides the shape, so a shape that serves no caller gets deleted and a shape two callers read differently gets split.

A refactor must lock current behavior before it moves code: a regression test that fails on the old shape and passes on the new one, or a recorded before/after run. Flag any restructure with no behavior lock, however clean it reads.

Every finding states the behavior at stake and its proof: the test output, the repro steps, or the spec line. Style without a behavioral consequence is a nit at most. If the intended behavior is not evident from the diff and its tests, grill for intent first instead of guessing (the grilling skill owns the interview); a review that invents intent manufactures findings.

What to review, in priority order

Read the target first, then judge it against these dimensions. The order is the triage order: a broken hook outranks an awkward prop. Expanded checklists with repo examples live in references/dimensions.md.

  1. Correctness of hooks and rendering: hooks called unconditionally and in stable order, stable key values, no state that duplicates derivable data, effects that clean up async work which can outlive unmount. Prefer derived values, maps, and explicit state models over effects that sync state step by step; effects that touch the world stay effects. Name the machine when two or more flags jointly decide one UI outcome: separate boot from op pending, never let undefined mean a screen, type the union once and export it, and give every async transition one owner with a generation check so a late response cannot overwrite newer state. See useCopyFeedback-style timers as the model: ref-held, cleared on retrigger and on unmount.
  2. Composition over configuration: layout shells take children, related pieces compose as compound components, call sites pass layout only. A pile of boolean props that switches between renders is a component begging to be split; a new showHeader or renderActions prop where the caller could pass children is the violation to name. Wrappers own styling; call sites never restyle. An abstraction earns its place only if deleting it would move meaningful complexity into its callers; a wrapper forwarding props unchanged with no logic gets inlined.
  3. Colocation: logic lives next to its only consumers: helpers beside their single call site, tables beside the rows they render, maps beside the registry they index. A shared module with one importer is a file waiting to be inlined. Each concept keeps one defining home; reuse the existing component, token, validator, or query instead of making another version. Flag duplicated status literals, magic strings, and route paths; one validator or helper owns each.
  4. State ownership: props for one level of passing, context (read through use(), never useContext) when it goes deeper. A component that renders from optional data owns its guard and returns null instead of pushing conditionals to its caller. Each component destructures only what it reads. When a module splits, every state transition keeps one owner; siblings never duplicate controlled state or callbacks.
  5. Repo idioms: React Compiler owns memoization, so useMemo, useCallback, and React.memo never appear (ADR-0009). Prefer function declarations over arrow function expressions, except in-component handlers, inline callbacks, and one-liners. Layout shells type props as React.ComponentProps<element>; data carriers keep explicit types. Multi-line event logic lives in named handle* functions; single-expression delegation stays inline. Props are Readonly, types beat interfaces, and nothing is ever cast.
  6. Dead code: a prop with zero call sites gets deleted, an unused helper goes with it. Extraction waits for the third copy: the first duplication is a note, the second is a candidate, the third is the refactor.

Escalation triggers: flag on sight

These are almost always wrong. You do not need to deliberate. Wrong-to-right snippets for each trigger live in references/triggers.md.

  • useMemo, useCallback, or React.memo.
  • useContext (the repo reads context through use()).
  • An as cast or a non-null assertion.
  • Omit that redeclares props just to re-add them, or a ...rest spread (the spread is named ...props).
  • children riding inside the spread instead of destructured and rendered.
  • Multi-line logic inline in onClick or JSX instead of a named handler.
  • A prop drilled through an intermediary that never reads it (context instead).
  • Nullable useState whose value reaches render without narrowing through a union.
  • A catch whose body only swallows, with no state update.
  • Arrow function declarations for components or module helpers (in-component handlers, inline callbacks, and one-liners are exempt).
  • Async setState after an await with no generation check, so a late response can overwrite newer state.
  • One boolean read two ways (boot versus op, page versus button).
  • A nullable phase where undefined means a different screen instead of missing data.

Output format

Lead with the verdict, then the findings. Do not bury the one thing that matters under ten nits.

  • Verdict: one line: Blocked, Approve with changes, or Ship it. Blocked means at least one finding breaks hooks, data flow, or the repo lint gate.
  • Blocking: findings that must be fixed before the code lands. Each: what is wrong, where (file:line), the behavior at stake plus its proof, why it hurts, and the fix with the repo rule it follows.
  • Should fix: real structural problems that are not blockers. Same shape.
  • Nits: small polish, clearly labeled as optional.

Be specific and cite the exact code. "This component is hard to follow" is weak; "this page threads entry through four layers that never read it: provide it once through context and let each section read what it needs" is a review. Name the repo rule (an AGENTS.md row, a CODING_STANDARDS.md section, an ADR) so the fix is grounded, not invented.

What earns approval

A target ships when hooks are correct, pieces compose instead of configuring, logic sits next to its consumers, state has a clear owner, repo idioms hold, and nothing dead remains. Approval is the absence of findings, not the absence of effort. If you cannot find anything wrong, say so plainly.

04 同仓库更多 Skills