# React Nextjs Conventions

> Use when writing or reviewing React/Next.js: structure and naming, typing, hooks discipline, immutability, memo, server-state libraries, validation at boundaries, App Router, effects and security correctness, tests, boundaries and composition, further security surface, the Server Action result contract and idempotency.

- Skill: `techmefr/react-nextjs-conventions` (Agent Skill, multi-file: 18 files)
- Install (CLI): `npx get-skill add techmefr/react-nextjs-conventions`
- Raw SKILL.md: https://api.skillmd.com/api/skills/techmefr/react-nextjs-conventions/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Web & Frontend
- Author: techmefr (https://skillmd.com/u/techmefr)
- Updated: 2026-11-19
- Page: https://skillmd.com/skills/techmefr/react-nextjs-conventions

---


# react-nextjs-conventions

Step 6 of the pipeline (`WORKFLOW.md`). Frames the writing of code on the React 18/19 + Next.js stack. Every
rule below holds in a repo with **nothing installed** (`CONVENTIONS.md`, rule A). Complementary to `legolas`
(the diff review agent): here we write the code, legolas re-reads it afterwards.

**Relation to an org skill catalogue.** Where a company ships its own versioned catalogue for this stack, it
is the authority on **its** house style and overrides this block wherever the two differ. This block is the
generic default. Two house conventions in particular genuinely split across real codebases — `type` vs
`interface` for object shapes, and where tests live — and this block says "pick one and apply it uniformly"
rather than pretending there's a universal answer.

**An applied override is recorded, not hidden.** Write the code the governing rule actually requires, and
leave one short neutral trace addressed to whoever can decide (a line in the PR description, the task summary
or an ADR): which rule was overridden, by what, and that it is a resolved case. Never phrase it as "a conflict
between mentis and the house rules" to a non-technical stakeholder — that framing reads as broken even when
the case is a normal, resolved one, and has already caused a real project to get abandoned and restarted over
nothing. Raise one specific, named question to the decider only when no rule anywhere actually resolves the
case.

**On a Laravel + Inertia.js app with React pages, there is no Next.js runtime** (no App Router, no
Next data fetching) — a page there is a plain component wired by Inertia. This block's Next-specific
sections don't have an equivalent in that architecture; see `skills/inertia-conventions` §4 before
flagging an Inertia repo against them.

## When
As soon as a `.tsx` component, a Next.js route, a hook, a store slice or a query hook is written or modified,
during `code` (6) or `tdd` (5).

## Steps

**Read only the sections the task actually touches.** The rules live one file per section under
`references/`; loading all of them for a change that only renames a variable is waste, and a section
read is a section that has to be applied. If you are reviewing a whole diff, pick the rows whose
trigger the diff meets, not the whole table.

| § | Covers | Read it when | File |
|---|---|---|---|
| 1 | Components and files | a component is created or split | [`01-components-files.md`](./references/01-components-files.md) |
| 2 | Naming | a symbol or a file has to be named | [`02-naming.md`](./references/02-naming.md) |
| 3 | Typing | props, state or a generic is typed | [`03-typing.md`](./references/03-typing.md) |
| 4 | Control flow | conditional rendering, lists, early returns | [`04-control-flow.md`](./references/04-control-flow.md) |
| 5 | State, effects, hooks | a hook is written, or an effect added | [`05-state-effects-hooks.md`](./references/05-state-effects-hooks.md) |
| 6 | Server state and stores | TanStack Query, Zustand or RTK | [`06-server-state-stores.md`](./references/06-server-state-stores.md) |
| 7 | Next.js | the App Router, a server component, a route handler | [`07-next-js.md`](./references/07-next-js.md) |
| 8 | The component library | a UI element is built, or custom CSS is about to be written | [`08-component-library.md`](./references/08-component-library.md) |
| 9 | Security, never negotiable | always, on any diff | [`09-security-never-negotiable.md`](./references/09-security-never-negotiable.md) |
| 10 | Accessibility and bundle weight | a control is rendered, or a dependency added | [`10-accessibility-bundle-weight.md`](./references/10-accessibility-bundle-weight.md) |
| 11 | Testing components and hooks | a component, a hook, a form or a data-fetching screen gets a test | [`11-testing.md`](./references/11-testing.md) |
| 12 | Boundaries, composition, context, forms, refs | a failure or loading state is contained, a context or compound component is introduced, a form, portal or ref is built, an external store is subscribed to | [`12-boundaries-composition-forms.md`](./references/12-boundaries-composition-forms.md) |
| 13 | Further security surface | a link opens a new window, inline data is shipped to the browser, an outside object is merged, a third-party script or widget is added, or the production build is configured | [`13-security-surface-extra.md`](./references/13-security-surface-extra.md) |
| 14 | Next.js 16 Cache Components | `cacheComponents` is on, a route sets `dynamic`/`revalidate`/`fetchCache`, `"use cache"` appears, or a 15 app moves to 16 | [`14-cache-components.md`](./references/14-cache-components.md) |
| 15 | The Server Action result contract and idempotency | a Server Action is written or reviewed: its return type, how it reports failure, what a second run does, what a deployment does to an open form | [`15-server-action-contract.md`](./references/15-server-action-contract.md) |
| 16 | Rendering and runtime performance | a list grows, an interaction lags, a scroll or input handler is added, or something re-renders too often | [`16-rendering-runtime-performance.md`](./references/16-rendering-runtime-performance.md) |

§16 overlaps §5 (when to memoise), §10 (what a dependency adds to the bundle) and §12 (lazy-loading a heavy component): the rule stays in the section that owns it, and §16 keeps only the runtime cost of rendering. Measure first with `skills/webperf`.

## Output / checkpoint
Code compliant with the sections above. No dedicated checkpoint: compliance is checked by `gate` (7) and by
`legolas` at review time in the `review` step (8).

## Guardrails
No comments in the code produced. Never modify a generated component file in place: always go through a
wrapper. Don't duplicate an existing hook or selector before checking that no nearby one covers the need.
This block writes code, it doesn't review diffs; for the review, that's `legolas`. Where an org catalogue is
installed and disagrees with a rule here, **it wins** — apply it and leave the short neutral trace described at the top, never a silent override. When in doubt about a rule covered by neither, escalate rather than guess.

## Origin
Rules mined from market catalogues, linters and internal review feedback, rewritten in the house
voice; the full provenance, the source stamps and the refresh log are in
[`references/origin.md`](./references/origin.md). Read it when checking whether a rule is still
current, not when applying one.

