Skip to main content
React 19 & Modern HooksfrontendTarget: React 19.x

React 19 Modern Hooks & Compiler AI Agent Rules

Modernize AI coding agents for React 19 Compiler and Server Component architectures.

Eliminate obsolete React patterns. Teach AI models to write modern React 19 code using useActionState, useOptimistic, and clean unidirectional data flow.

#react cursorrules#react 19 cursor rules#react claude md#react agent rules#cursor rules for react

Configuration Workbench

Select your agent format below to preview, copy, or download the configuration file.

Cursor configuration for React 19 projects.
15 lines•0.8 KB
# React 19 Cursor Rules

You are a Principal React 19 and TypeScript engineer.

## React 19 Primitives
- Rely on the React Compiler: Do NOT wrap functions in 'useCallback' or values in 'useMemo' by default.
- Pass 'ref' directly as a prop to function components. Do NOT use deprecated 'forwardRef'.
- For forms and async transitions, use 'useActionState', 'useFormStatus', and 'useOptimistic'.
- Use the 'use' hook for reading promises and React context conditionally or inside loops.

## Code Quality
- Functional components only. Zero class components.
- Strict TypeScript typing with explicit props interfaces.
- Accessibility: ARIA attributes, semantic buttons (type='button'|'submit'), keyboard navigable.
- Clean component breakdown: No monolithic files over 200 lines.

Pro-tip: Place this file directly in the root directory of your React 19 & Modern Hooks project. AI agents like Cursor Composer, Claude Code, and GitHub Copilot will read it automatically on initialization.

Architectural Principles Enforced

When this configuration file is loaded into Cursor or Claude Code, the agent strictly enforces the following design invariants:

Leverage the React 19 Compiler: Avoid premature `useMemo` and `useCallback` unless isolating expensive external libraries.

Use `useActionState` instead of complex `useState` + `useEffect` combinations for asynchronous form submissions.

Implement `useOptimistic` for instantaneous UI feedback during network mutations.

Use `ref` as a standard prop; do not use the deprecated `forwardRef` API in React 19.

Clean separation of pure presentation components from stateful data hooks.

Installation & Repository Setup

Place in project root as `.cursorrules` or `.cursor/rules/react.mdc`.

1Download or copy `.cursorrules` into your project root.
2Add to version control to standardize team AI coding style.

Verified Agent Behavior Examples

Observe how the AI agent responds when prompted under these active rules.

Scenario: Creating an optimistic todo item toggle
User prompt: “Build a todo checkbox that toggles instantly while calling the server in the background.”
Agent Behavior: The agent implements `useOptimistic` to flip the UI state immediately, cleanly falling back if the background action fails.

Frequently Asked Questions

Is forwardRef still needed in React 19?

No. In React 19, `ref` can be passed as a standard prop directly to functional components. `forwardRef` is deprecated and will be removed in future releases.