- Home
- Skills
- Code Quality & Review
- react antipatterns review
Works with the AI Agents you already use
react antipatterns review
Audit React components for architectural anti-patterns, hook misuses, and performance bottlenecks with a fix plan.
Free
react antipatterns review
Example session with this skill installed
Review my RequestForm.tsx component for any React anti-patterns. Just show the results here in the chat.
- Read your context and instructions
- Compiled the react antipatterns review
- Generated the UI component
React anti-pattern review
Scope: client/src/pages/RequestForm.tsx · 4 findings (0 High · 2 Medium · 2 Low) · catalog v2
Assumptions: React 19.2.7 (from client/package.json), no React Compiler (vite.config.ts uses plain @vitejs/plugin-react), web.
No C1, D4, D7 or D8. FieldError is declared at module scope, every hook runs before the early returns, and every state update is immutable. handleSubmit reads values before its await, which is intended: it submits what was on screen at the click.
client/src/pages/RequestForm.tsx
F1 [MEDIUM] Hydrating form state from fetched data in an Effect — A2, D6 (lines 159, 167–172)
What: hydrated state plus useEffect(() => { if (existing && !hydrated) { setValues(toFormValues(existing.values)); setHydrated(true); } }, [existing, hydrated]).
Why it's flagged: values is seeded from existing, and an Effect copies it across after the render. When the fetch resolves, the first render passes every guard with values === EMPTY_VALUES. That render can paint an empty edit form before the Effect fills it in. It also re-renders twice: once for setValues and once for setHydrated. hydrated never appears in the JSX. It only gates the Effect, so it causes a re-render for a value nothing displays (D6).
Fix: Split the component into a loader and a form. The loader fetches and runs the guards. The form takes the fetched values as a seed, the pattern the catalog allows, so hydrated and the Effect go away.
// before
const [values, setValues] = useState(EMPTY_VALUES);
const [hydrated, setHydrated] = useState(!loadId);
useEffect(() => { /* copy existing → values */ }, [existing, hydrated]);
// after (loader renders this once data and guards pass)
<RequestFormFields key={loadId ?? 'new'} initialValues={existing ? toFormValues(existing.values) : EMPTY_VALUES} ... />
// inside: const [values, setValues] = useState(initialValues);
For a smaller change, adjust state during render with a guard. Write if (existing && !hydrated) { setHydrated(true); setValues(...) } in the body, not in an Effect. React then re-renders before paint, so the empty frame never shows.
F2 [MEDIUM] fieldErrors derived from values via an Effect — A1 (lines 164, 177–183)
What: useEffect(() => { if (!submitAttempted) return; setFieldErrors(validate(values)); }, [values, submitAttempted]). setFieldErrors is also called from handleSubmit (lines 253, 258) and handleWriteError (line 226).
Why it's flagged: Client-side errors are a pure function of values and submitAttempted, so they are derived state. Each keystroke after the first submit renders once with stale errors, then the Effect re-renders. handleSubmit also validates twice: once inline and again when the Effect reacts to setSubmitAttempted(true). Three writers share one state slot: the Effect, the submit handler and the server error handler. Which source wins depends on timing. The Effect also returns early when submitAttempted is false. So server fieldErrors from a failed Save Draft never clear while the user types.
Fix: Compute client errors during render. Keep only server errors in state, and clear them in the change handler.
const [serverErrors, setServerErrors] = useState<FieldErrors>({});
const clientErrors = submitAttempted ? validate(values) : {};
const fieldErrors = { ...clientErrors, ...serverErrors };
function setField(key, value) {
setValues((prev) => ({ ...prev, [key]: value }));
setServerErrors({});
}
handleSubmit then calls validate(values) once, to decide whether to POST and which field to focus. It no longer writes errors to state.
F3 [LOW] Two booleans for one write status — D9 (lines 161–162, 190)
What: isSubmitting and isSaving, combined into busy.
Why it's flagged: The two flags describe one mutually exclusive phase: idle, saving or submitting. The default severity is Medium. I lowered it to Low because both buttons are disabled when busy is true, so no UI path sets both flags at once.
Fix: const [pending, setPending] = useState<'idle' | 'saving' | 'submitting'>('idle'); const busy = pending !== 'idle';
F4 [LOW] Non-unique key on the error list — E1 (lines 443–447)
What: unshownErrors.map((message) => <p key={message}>…).
Why it's flagged: unshownErrors flattens messages from several fields. Two hidden fields can return the same message text, for example "Required". React then warns about duplicate keys and can drop or duplicate a row. The rows hold no state, so the impact is cosmetic.
Fix: Keep the field name when flattening, and key on it plus the index: .flatMap(([field, msgs]) => msgs.map((m, i) => ({ key: `${field}-${i}`, m }))).
Outside the catalog / worth a look
loadIdandrequestIdare seeded fromrouteId(lines 150, 158). This matches the A12 signal, but it is an intentional seed, and the comment explains why. It is safe today only because no link goes directly from/requests/:id/editto/requests/newor to another edit URL. Both routes render<RequestForm />at the same position, so React Router reuses the mounted instance. If someone adds such a link later, for example in the header, the reused form keeps the oldrequestIdand Save writes to the wrong request. Akey={routeId}on the loader from F1, with the post-createnavigatehandled separately, would remove this dependency.useApiQueryinitialisesloadingtofalse(this is inapi/useApiQuery.ts, not this file). On the first render of an edit URL,loadingis false andexistingis null. IfcurrentUseris already set, the guard at line 274 passes and the empty form renders for one frame before the fetch starts. This makes the F1 flash worse. Starting withuseState(path !== null)would fix it.
Summary
No High-severity bugs. The main theme is derived state kept in sync by Effects. The form values are copied in from the fetch (F1), and the validation errors are copied in from values (F2). Both cause extra renders and timing-dependent desync. Fix F2 first: it is small and contained. F1 is the bigger structural change, and it also covers the route-reuse note.
Fix plan
[ ] 1. Derive client validation errors during render; keep only server errors in state — fixes F2
- Where:
RequestForm: state at line 164, Effect at lines 177–183,setField,handleSubmit,handleWriteError - Effort: S
- Check it worked: Submit an empty form, then type a valid amount. The amount error clears on that keystroke with no extra render. Force a server
fieldErrorsresponse; it appears, then clears on the next edit.
[ ] 2. Split the component into a loader and a seeded form, and delete the hydrated Effect — fixes F1
- Where:
RequestForm: lines 150–172 plus the guards at lines 274–302 - Effort: M
- Check it worked: Throttle the network and open
/requests/REQ-001/edit. The page shows "Loading request..." and then the filled form, with no empty frame between them. Save Draft on a new request still turns into a PATCH on retry. - Note: Do this after step 1, so the split moves the simpler error logic. Giving the loader a
keyalso covers the route-reuse risk under "worth a look".
Optional clean-up (Low)
- Replace
isSaving/isSubmittingwith a singlependingstatus — F3 - Give the hidden-field error list unique keys — F4
RequestForm.tsx
TSX · React component
Example file from a real run - the skill writes it into your workspace.
Connects securely to your tools. The creator never sees your data.
About this skill
React Anti-Patterns Review
An Agent Skill that reviews React / JSX / TSX code for known anti-patterns and hands you a prioritized fix plan. It is observe-only: it never edits your source files.
Point it at a component, a pasted snippet, a diff or a PR, and you get a file-by-file walkthrough of numbered findings (each tied to a catalog ID, with the reasoning and a small before → after snippet), a short summary, and a checklist-style fix plan ordered by priority.
Why observe-only?
People usually want to know what's wrong and what to do about it before touching the code: a PR they're reviewing, a teammate's component, a file they can't change yet. So the skill explains and plans, and stops. If you want the fixes applied, ask for that as a separate step.
What it checks
The catalog (references/catalog.md, v2) covers 29 anti-patterns, each with a stable ID, a default severity, why it matters, how to fix it, and a list of legitimate uses so it doesn't flag false positives.
| Group | IDs | Examples |
|---|---|---|
| State & Effects | A1–A12 | Derived state, event logic in Effects, chained Effects, fetching without cleanup, prop copied into state |
| Memoization | B1–B4 | useMemo/useCallback that feed nothing, memoizing cheap operations |
| Component structure | C1 | Component defined inside another component |
| Hooks & state shape | D1–D9 | Missing deps, conditional hooks, stale closures, direct mutation, several booleans for one status |
| Rendering, lists & context | E1–E3 | key={index}, && with a number, mega-contexts and unstable provider values |
It also adapts advice to your project when it can see it: React version (e.g. useEffectEvent only on 19.2+), whether React Compiler is on (memoization findings are skipped), React Native vs web, and which data-fetching library you already use.
Usage
You don't need to name the skill. Any React review or hook question triggers it:
Review src/components/TodoList.tsx for anti-patterns
Why does this component re-render so much? [paste code]
Check the React changes in this PR before I merge
Before reviewing, it asks one question: show the review and plan in the chat (default), or also save them as a Markdown file? Skip the question by saying it up front, e.g. "review this and save it to a file" or "just show me".
Saved files are named react-review-<scope>-<YYYY-MM-DD>.md and placed in your project root. Existing files are never overwritten.
Accepted input: files on disk or uploaded, pasted snippets, diffs and PRs, or a source file open in Chrome.
Example output
# React anti-pattern review
Scope: TodoList.tsx · 3 findings (1 High · 1 Medium · 1 Low) · catalog v2
Assumptions: React 18, no compiler
## src/components/TodoList.tsx
### F1 [HIGH] Rows keyed by index — E1 (line 42)
**What:** `todos.map((t, i) => <TodoRow key={i} ... />)`
**Why it's flagged:** rows can be deleted and each holds an input's state, so deleting row 1 shifts row 2's text into it.
**Fix:** `key={t.id}`
...
## Fix plan
### [ ] 1. Key rows by `todo.id` — fixes F1
- **Where:** TodoList
- **Effort:** S
- **Check it worked:** delete the first row; the second row's input keeps its text
File structure
| File | Purpose |
|---|---|
SKILL.md | Entry point: workflow, scan checklist, rating rules |
references/catalog.md | Every anti-pattern with ID, severity, fix and legitimate uses |
references/report-format.md | Report template, fix-plan template, file delivery rules |
Sources
The catalog draws on:
- You Might Not Need an Effect (react.dev)
- Separating Events from Effects (react.dev)
- Updating Objects in State (react.dev)
- How to useMemo and useCallback (developerway.com)
Does not modify source code or provide inline annotations. Focuses on React-specific logic rather than general CSS, styling, or accessibility audits.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before any payment.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Free forever
No account required to browse
Trust & safety
Security scan
Security scan passed today
- Free with an Agensi account
Requires