React (web)
React web applications.
Web React. Nearly half its rules are about hooks discipline — derived state synced via useEffect instead of computed during render, missing effect cleanup, conditional hook calls, exhaustive-deps disabled — because that's where render-cycle bugs hide. The rest cluster around state correctness (direct mutation, index keys on reorderable lists, server data copied into local state) and render performance (barrel imports, statically-imported heavy components, sequential awaits that should be parallel).
Which repositories get it
A repository on any of these 4 profiles: fullstack-react-node, mobile-react-native, web-nextjs, web-react. redline init detects the profile and --profile overrides it — see Profiles & stacks.
Within such a repository, a file gets these rules when it matches one of these globs:
**/*.tsx**/*.jsxsrc/**/*.tsapp/**/*.tspackages/**/src/**/*.tsapps/**/src/**/*.ts
The 32 rules
When a review comment cites one of these ids, this is where to look up what it catches. Of the 32, 13 BLOCKER, 13 HIGH and 6 SUGGESTION. A finding from this file opens like this:
Redline/BLOCKER [react/effect-derived-state]: <one-line problem>What each severity obliges you to do is on The output contract.
| Rule id | Severity | Catches |
|---|---|---|
react/effect-derived-state | BLOCKER | `useEffect` for derived state. State computable from existing props/state must be computed during render, never synced via effect. |
react/effect-for-event-logic | BLOCKER | `useEffect` for event logic. Notifications, analytics, navigation triggered by a user action belong in the event handler, not an effect watching state. |
react/missing-effect-cleanup | BLOCKER | Missing `useEffect` cleanup for subscriptions, timers, listeners, and in-flight requests (AbortController). |
react/direct-state-mutation | BLOCKER | Direct state mutation (`arr.push`, `obj.x =`, `.splice`) followed by `setState` — silent update failure. |
react/conditional-hook-calls | BLOCKER | Conditional hook calls — hooks inside `if`, loops, or early returns. |
react/key-is-index | BLOCKER | `key={index}` on lists that reorder, insert, or delete. |
react/server-data-in-local-state | BLOCKER | Server data copied into local state. With TanStack Query / SWR, the query result IS the source of truth — never `useEffect(() => setLocal(data))`. |
react/nested-component-definition | BLOCKER | Component defined inside another component — remounts every render, loses state. |
react/useformstatus-placement | BLOCKER | `useFormStatus` in the same component that renders the `<form>` — always returns `pending: false`; must be in a child. |
react/promise-in-render | BLOCKER | Promise created during render passed to `use()` — infinite loop; promise must come from props, state, or cache. |
react/exhaustive-deps-disabled | BLOCKER | `eslint-disable react-hooks/exhaustive-deps` — hides stale-closure bugs; require refactor instead. |
react/set-state-in-render | BLOCKER | A state setter called during render — unconditionally in the component body, or called instead of passed in a handler prop (`onClick={setOpen(true)}`). It schedules a render from inside render and loops until React throws "Too many re-renders". Derive the value during render, or pass a function (`onClick={() => setOpen(true)}`). Not the documented guarded pattern (`if (items !== prevItems) { setPrevItems(items); … }`). |
react/javascript-url | BLOCKER | A `javascript:` URL, or an unvalidated user-supplied URL, in `href`/`src`/`action`/`formAction`. Before React 19 a stored `javascript:` profile link runs in the viewer's session; React 19 blocks it and a literal `javascript:void(0)` throws on click. Use `<button type="button" onClick>` for actions and allow-list `http:`/`https:`/relative URLs for user links. |
react/incomplete-dependency-array | HIGH | Incomplete dependency arrays (stale closures). |
react/sequential-awaits | HIGH | Sequential `await`s for independent operations — require `Promise.all`. |
react/barrel-file-imports | HIGH | Barrel-file imports (`import { X } from '@/components'`) — require direct imports; barrels bloat bundles and cause circular deps. |
react/heavy-component-static-import | HIGH | Heavy components (charts, editors, modals) imported statically — require `next/dynamic` / `React.lazy`. |
react/uncontrolled-to-controlled | HIGH | `useState(undefined)` for controlled inputs — uncontrolled→controlled warning; use `''`. |
react/missing-error-boundary | HIGH | Missing Error Boundary around subtrees that fetch or can throw. |
react/falsy-and-rendering | HIGH | `&&` conditional rendering with a possibly-falsy non-boolean left side (`count && <X/>` renders `0`) — require ternary or explicit boolean. |
react/async-effect-callback | HIGH | An `async` function passed straight to `useEffect`/`useLayoutEffect`. The effect returns a Promise where React expects a cleanup, so nothing can cancel it: the slower "hell" response lands after "hello" and overwrites its results. Declare the async function inside, call it, and return a cleanup that sets an `ignore` flag or aborts. |
react/impure-render | HIGH | A non-deterministic value or global write during render — `Math.random()`, `Date.now()`/`new Date()`, `crypto.randomUUID()` read in the body, or a module/`window` variable assigned. Output differs between renders and between server and client; a random `key` remounts the subtree every render, dropping focus and state. Use `useId` or a lazy `useState(() => …)`, and move clock reads and writes into effects or handlers. |
react/ref-access-in-render | HIGH | `ref.current` read or written during render. A ref change does not re-render, so a value shown from it is stale, and a write from a render React discards still sticks. Use refs in effects and handlers and state for anything on screen. Not the lazy-init guard `if (ref.current === null) ref.current = …`. |
react/try-catch-around-jsx | HIGH | `try`/`catch` around returned JSX as error handling for children. Children render after the parent returns, so the catch never sees their errors and the fallback never shows — the page goes blank. Wrap the subtree in an Error Boundary. Not when the `try` wraps a computation this component really runs. |
react/unstable-context-value | HIGH | An object, array or function literal as a context provider `value`. It gets a new identity every render, so every consumer re-renders — at the app root, on every keystroke anywhere in root state. Memoise it (`useMemo`/`useCallback`) or hoist it. Not where React Compiler is enabled for the file. |
react/object-default-prop | HIGH | An array, object or function literal as a destructured prop default (`{ items = [] }`). Each render gets a new identity, so a dependent hook re-runs every render — and loops forever if it sets state. Hoist a module constant (`const EMPTY: Item[] = []`). |
react/trivial-memoisation | SUGGESTION | `useMemo`/`useCallback` wrapping trivial primitives — remove. |
react/missing-lazy-initialiser | SUGGESTION | Expensive `useState` initializer without lazy init — pass a function. |
react/starttransition-for-non-urgent | SUGGESTION | `startTransition` for non-urgent updates driving expensive renders. |
react/oversized-component | SUGGESTION | Component over ~300 lines — suggest split. |
react/prop-drilling | SUGGESTION | Prop drilling beyond 2–3 levels — suggest composition or context. |
react/prefer-ref-over-state | SUGGESTION | Interaction state read only inside callbacks — use a ref, not state, to avoid re-renders. |
Changing a rule
Edit standards/stacks/react.md and nowhere else. Every other copy is generated from it. A merged change reaches every onboarded repository as a pull request, so treat it as a production change.
Rule ids are permanent. Reword a rule freely; it keeps its id. Renaming or removing an id orphans every telemetry record that cited it.
- Edit the markdownstandards/ is the only place a human edits a rule. AGENTS.md, CLAUDE.md, .github/copilot-instructions.md and .github/instructions/ are rendered from it, and the next render overwrites any hand edit there.
- node scripts/assign-rule-ids.mjsAssigns a permanent <stack>/<slug> id to any new rule bullet and rewrites the file in place. Do not invent an id by hand. CI runs the same script with --check and fails if a rule is missing one.
- node scripts/render-self.mjsRe-renders this repository's own copies of those files. CI runs it with --check, so a stale copy fails the build.
- Bump standards/manifest.json → versionIn the same pull request as the rule change. Sync pull requests quote the version, so every repository can tell which standards it is on.
- Add a CHANGELOG.md entryAlso in the same pull request. Say what changed and why, and record the seed score: a standards change with no measurement is an opinion.
- node scripts/validate.mjsThe self-check CI runs: the manifest is consistent, rule ids are well formed, the output contract is intact, and every glob is one Copilot can read.
Related
- The output contract — what each severity obliges you to do.
- Profiles & stacks — how a repository ends up with a set of rules.
- Seeded corpus: react — the known-bad code that tests whether reviewers catch these rules.
- All standards
The full file
# React Review Rules
**Scope:** web React. Where a file is also matched by the React Native rules, the
React Native rules extend these — they do not replace them. Do not flag web-only
concerns (DOM, `next/dynamic`, bundle splitting) on React Native files.
## BLOCKER — request changes
- `react/effect-derived-state` — **`useEffect` for derived state.** State computable from existing props/state must be computed during render, never synced via effect.
```tsx
// WRONG
useEffect(() => { setFullName(first + ' ' + last); }, [first, last]);
// RIGHT
const fullName = first + ' ' + last;
```
- `react/effect-for-event-logic` — **`useEffect` for event logic.** Notifications, analytics, navigation triggered by a user action belong in the event handler, not an effect watching state.
- `react/missing-effect-cleanup` — **Missing `useEffect` cleanup** for subscriptions, timers, listeners, and in-flight requests (AbortController).
- `react/direct-state-mutation` — **Direct state mutation** (`arr.push`, `obj.x =`, `.splice`) followed by `setState` — silent update failure.
- `react/conditional-hook-calls` — **Conditional hook calls** — hooks inside `if`, loops, or early returns.
- `react/key-is-index` — **`key={index}`** on lists that reorder, insert, or delete.
- `react/server-data-in-local-state` — **Server data copied into local state.** With TanStack Query / SWR, the query result IS the source of truth — never `useEffect(() => setLocal(data))`.
- `react/nested-component-definition` — **Component defined inside another component** — remounts every render, loses state.
- `react/useformstatus-placement` — **`useFormStatus` in the same component that renders the `<form>`** — always returns `pending: false`; must be in a child.
- `react/promise-in-render` — **Promise created during render passed to `use()`** — infinite loop; promise must come from props, state, or cache.
- `react/exhaustive-deps-disabled` — **`eslint-disable react-hooks/exhaustive-deps`** — hides stale-closure bugs; require refactor instead.
- `react/set-state-in-render` — **A state setter called during render** — unconditionally in the component body,
or called instead of passed in a handler prop (`onClick={setOpen(true)}`). It schedules a render from inside
render and loops until React throws "Too many re-renders". Derive the value during render, or pass a function
(`onClick={() => setOpen(true)}`). Not the documented guarded pattern (`if (items !== prevItems) {
setPrevItems(items); … }`).
- `react/javascript-url` — **A `javascript:` URL, or an unvalidated user-supplied URL, in
`href`/`src`/`action`/`formAction`.** Before React 19 a stored `javascript:` profile link runs in the viewer's
session; React 19 blocks it and a literal `javascript:void(0)` throws on click. Use `<button type="button"
onClick>` for actions and allow-list `http:`/`https:`/relative URLs for user links.
## HIGH
- `react/incomplete-dependency-array` — Incomplete dependency arrays (stale closures).
- `react/sequential-awaits` — Sequential `await`s for independent operations — require `Promise.all`.
- `react/barrel-file-imports` — Barrel-file imports (`import { X } from '@/components'`) — require direct imports; barrels bloat bundles and cause circular deps.
- `react/heavy-component-static-import` — Heavy components (charts, editors, modals) imported statically — require `next/dynamic` / `React.lazy`.
- `react/uncontrolled-to-controlled` — `useState(undefined)` for controlled inputs — uncontrolled→controlled warning; use `''`.
- `react/missing-error-boundary` — Missing Error Boundary around subtrees that fetch or can throw.
- `react/falsy-and-rendering` — `&&` conditional rendering with a possibly-falsy non-boolean left side (`count && <X/>` renders `0`) — require ternary or explicit boolean.
- `react/async-effect-callback` — **An `async` function passed straight to `useEffect`/`useLayoutEffect`.** The
effect returns a Promise where React expects a cleanup, so nothing can cancel it: the slower "hell" response
lands after "hello" and overwrites its results. Declare the async function inside, call it, and return a
cleanup that sets an `ignore` flag or aborts.
- `react/impure-render` — **A non-deterministic value or global write during render** — `Math.random()`,
`Date.now()`/`new Date()`, `crypto.randomUUID()` read in the body, or a module/`window` variable assigned.
Output differs between renders and between server and client; a random `key` remounts the subtree every
render, dropping focus and state. Use `useId` or a lazy `useState(() => …)`, and move clock reads and writes
into effects or handlers.
- `react/ref-access-in-render` — **`ref.current` read or written during render.** A ref change does not
re-render, so a value shown from it is stale, and a write from a render React discards still sticks. Use refs
in effects and handlers and state for anything on screen. Not the lazy-init guard `if (ref.current === null)
ref.current = …`.
- `react/try-catch-around-jsx` — **`try`/`catch` around returned JSX as error handling for children.** Children
render after the parent returns, so the catch never sees their errors and the fallback never shows — the page
goes blank. Wrap the subtree in an Error Boundary. Not when the `try` wraps a computation this component
really runs.
- `react/unstable-context-value` — **An object, array or function literal as a context provider `value`.** It
gets a new identity every render, so every consumer re-renders — at the app root, on every keystroke anywhere
in root state. Memoise it (`useMemo`/`useCallback`) or hoist it. Not where React Compiler is enabled for the
file.
- `react/object-default-prop` — **An array, object or function literal as a destructured prop default** (`{
items = [] }`). Each render gets a new identity, so a dependent hook re-runs every render — and loops forever
if it sets state. Hoist a module constant (`const EMPTY: Item[] = []`).
## SUGGESTION
- `react/trivial-memoisation` — `useMemo`/`useCallback` wrapping trivial primitives — remove.
- `react/missing-lazy-initialiser` — Expensive `useState` initializer without lazy init — pass a function.
- `react/starttransition-for-non-urgent` — `startTransition` for non-urgent updates driving expensive renders.
- `react/oversized-component` — Component over ~300 lines — suggest split.
- `react/prop-drilling` — Prop drilling beyond 2–3 levels — suggest composition or context.
- `react/prefer-ref-over-state` — Interaction state read only inside callbacks — use a ref, not state, to avoid re-renders.