CLAUDE.md rules for React 19 with TypeScript covering typed components, derived state, compiler-aware memoization, useId-based accessibility and review checks.
.claude/rules/claude-react-expert.md. Downloaded files need to be placed in that repository path.---
paths:
- "**/*"
---
# React and TypeScript Conventions
Applies to: React components, hooks and tests in this repository, written in TypeScript (including Next.js App Router client components).
Version baseline: checked against React 19.2, TypeScript 5.9, eslint-plugin-react-hooks 7 and React Compiler 1.0. Read `package.json`. If the project is on React 18, keep `forwardRef` and don't use React 19-only hooks (`useActionState`, `useOptimistic`, `useEffectEvent`).
## Writing components
1. Use function components with typed props (`type Props = {...}`). Don't use `React.FC` or `any`. Type events and refs precisely.
2. Give each component one job. Lift state only as far as the nearest common owner, and prefer composition (`children`, slots) over boolean prop flags.
3. Derive values during render. Don't copy props into state, and don't compute state inside `useEffect`.
4. Use effects only to synchronize with external systems, and always clean up. Use `useEffectEvent` for non-reactive logic called from an effect.
5. In React 19, `ref` is a regular prop, so don't add `forwardRef` to new components.
6. Memoization: if React Compiler is enabled, don't hand-write `useMemo`/`useCallback`/`memo`. Otherwise use them only for a measured slow computation or a referential-equality requirement.
7. For server-backed forms (React 19 or Next.js), prefer `useActionState`/`useFormStatus` for pending and error state.
## Accessibility (WCAG 2.2 AA)
- Use native elements first (`button`, `a`, `label`, `ul`) and add ARIA only when no native element fits. A `role` promises keyboard behavior, so implement it or don't use the role.
- Every input has a visible label or an accessible name. Generate ids with `useId()`, never hard-coded strings that collide when the component renders twice.
- Make interactive elements keyboard reachable with a visible focus style.
```tsx
import { useId, useState } from 'react';
type Item = { id: string; name: string };
type Props = {
title: string;
items: Item[];
onSelect: (item: Item) => void;
};
export function ItemList({ title, items, onSelect }: Props) {
const [filter, setFilter] = useState('');
const headingId = useId();
const query = filter.trim().toLowerCase();
const visible = query ? items.filter((i) => i.name.toLowerCase().includes(query)) : items;
return (
<section aria-labelledby={headingId}>
<h2 id={headingId}>{title}</h2>
<label>
Filter items
<input type="search" value={filter} onChange={(e) => setFilter(e.target.value)} />
</label>
<ul>
{visible.map((item) => (
<li key={item.id}>
<button type="button" onClick={() => onSelect(item)}>
{item.name}
</button>
</li>
))}
</ul>
{visible.length === 0 && <p role="status">No items match "{filter}".</p>}
</section>
);
}
```
## State and data
- Use server state libraries (TanStack Query, SWR or framework loaders) for remote data instead of `useEffect` + `fetch`.
- Use a client store (Zustand, Jotai) only for state shared across distant components, with narrow selectors.
## Tests
- Use Vitest or Jest with React Testing Library. Query by role and name, interact with `user-event`, and use `renderHook` from `@testing-library/react` for custom hooks.
## When reviewing code
Check type safety (`any`, unchecked casts), hook rule violations, missing cleanup, state that should be derived, accessibility (names, roles, keyboard, focus) and likely bugs such as stale closures and missing keys. Suggest performance changes only with evidence.
## Verify before finishing
Run when available: `npx tsc --noEmit`, `npx eslint .` (with `eslint-plugin-react-hooks` recommended config) and the test command.
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.
Claude
frontend
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Claude Code writes or reviews React components in a TypeScript app with this file loaded as a project rule (for example .claude/rules/react.md scoped to **/*.tsx).
Review and fix src/components/ItemList.tsx: it uses <ul role="listbox"> with <li role="option"> wrapping buttons, a hard-coded id="list-heading", useMemo for a three-item filter, and the list is rendered twice on the settings page. React 19.2, React Compiler enabled.
Illustrative; not a recorded model run. Review findings naming the ARIA misuse (listbox role without listbox keyboard behavior, interactive content inside options), the duplicate-id bug and unnecessary memoization under the compiler; a fixed component using a plain list of buttons, useId for the heading, a labelled search input, derived filtering in render and an empty-state status message; a Testing Library test querying by role/name; tsc, eslint (react-hooks recommended) and test results.
Claude Code loads persistent project instructions from CLAUDE.md files and from Markdown rules in .claude/rules/. Rules can be scoped to file paths with a paths frontmatter field, and CLAUDE.md can import other files with @path syntax. The rules in this directory are written as plain instruction prompts: in Claude Code, save them as CLAUDE.md or .claude/rules/ content; in Claude.ai or the Claude API, use the same text as project instructions or a system prompt instead.
.claude/rules/claude-react-expert.mdStarting point, not a tested configuration for your repository. Loaded when Claude Code works with files matching paths. Review the instructions, adapt the file paths and run your project's existing checks.
---
paths:
- "**/*"
---
# React and TypeScript Conventions
Applies to: React components, hooks and tests in this repository, written in TypeScript (including Next.js App Router client components).
Version baseline: checked against React 19.2, TypeScript 5.9, eslint-plugin-react-hooks 7 and React Compiler 1.0. Read `package.json`. If the project is on React 18, keep `forwardRef` and don't use React 19-only hooks (`useActionState`, `useOptimistic`, `useEffectEvent`).
## Writing components
1. Use function components with typed props (`type Props = {...}`). Don't use `React.FC` or `any`. Type events and refs precisely.
2. Give each component one job. Lift state only as far as the nearest common owner, and prefer composition (`children`, slots) over boolean prop flags.
3. Derive values during render. Don't copy props into state, and don't compute state inside `useEffect`.
4. Use effects only to synchronize with external systems, and always clean up. Use `useEffectEvent` for non-reactive logic called from an effect.
5. In React 19, `ref` is a regular prop, so don't add `forwardRef` to new components.
6. Memoization: if React Compiler is enabled, don't hand-write `useMemo`/`useCallback`/`memo`. Otherwise use them only for a measured slow computation or a referential-equality requirement.
7. For server-backed forms (React 19 or Next.js), prefer `useActionState`/`useFormStatus` for pending and error state.
## Accessibility (WCAG 2.2 AA)
- Use native elements first (`button`, `a`, `label`, `ul`) and add ARIA only when no native element fits. A `role` promises keyboard behavior, so implement it or don't use the role.
- Every input has a visible label or an accessible name. Generate ids with `useId()`, never hard-coded strings that collide when the component renders twice.
- Make interactive elements keyboard reachable with a visible focus style.
```tsx
import { useId, useState } from 'react';
type Item = { id: string; name: string };
type Props = {
title: string;
items: Item[];
onSelect: (item: Item) => void;
};
export function ItemList({ title, items, onSelect }: Props) {
const [filter, setFilter] = useState('');
const headingId = useId();
const query = filter.trim().toLowerCase();
const visible = query ? items.filter((i) => i.name.toLowerCase().includes(query)) : items;
return (
<section aria-labelledby={headingId}>
<h2 id={headingId}>{title}</h2>
<label>
Filter items
<input type="search" value={filter} onChange={(e) => setFilter(e.target.value)} />
</label>
<ul>
{visible.map((item) => (
<li key={item.id}>
<button type="button" onClick={() => onSelect(item)}>
{item.name}
</button>
</li>
))}
</ul>
{visible.length === 0 && <p role="status">No items match "{filter}".</p>}
</section>
);
}
```
## State and data
- Use server state libraries (TanStack Query, SWR or framework loaders) for remote data instead of `useEffect` + `fetch`.
- Use a client store (Zustand, Jotai) only for state shared across distant components, with narrow selectors.
## Tests
- Use Vitest or Jest with React Testing Library. Query by role and name, interact with `user-event`, and use `renderHook` from `@testing-library/react` for custom hooks.
## When reviewing code
Check type safety (`any`, unchecked casts), hook rule violations, missing cleanup, state that should be derived, accessibility (names, roles, keyboard, focus) and likely bugs such as stale closures and missing keys. Suggest performance changes only with evidence.
## Verify before finishing
Run when available: `npx tsc --noEmit`, `npx eslint .` (with `eslint-plugin-react-hooks` recommended config) and the test command.
Ask for a small change to one matching file. Check the tool's loaded context or instruction view, inspect the diff for the requested convention, and run the relevant build or test. A well-formatted file does not guarantee the model follows every instruction.
Imports with @path can nest up to four hops deep, according to the docs. Claude Code can read AGENTS.md as project instructions without extra configuration, but by default only when there is no CLAUDE.md in the working directory or above it. The docs list this behavior for version 2.1.277 and later and describe a setting (claude-md-and-agents-md) that loads both files. If you maintain AGENTS.md for other tools, you can also import it from CLAUDE.md with @AGENTS.md.
Documentation checked 2026-11-05: Claude Code docs: Manage Claude's memory
Cursor rules for Tailwind CSS v4: automatic class sorting, mobile-first breakpoints, CVA variants with merging, class-based dark mode via @custom-variant, and CSS-first @theme configuration.
Stack-neutral CLAUDE.md conventions for Claude Code covering how to read before editing, keep diffs scoped, debug from a reproduction, test and report verification.
Cursor rules for React with TypeScript: typed function components, React 19 ref-as-prop, hooks discipline, state ownership, error boundaries and measured performance work.