So
Sophie Alpert & React Community@sophiebitsCore Maintainer VerifiedReact Ecosystem

Specification Author & Maintainer • Verified via AgentRules Industrial Quality Gate

frontendhigh PriorityID: react-19-compiler

React 19 Compiler & Modern Hooks Architecture

Conventions for React 19: utilize React Compiler automatic memoization, replace boilerplate useMemo/useCallback, adopt useActionState, useOptimistic, and Server Actions.

Prohibited Anti-Pattern: AI wraps every primitive function in useCallback/useMemo out of habit and hallucinates legacy useEffect data fetching.

Export Ready-to-Drop Configuration

Select format below to copy code or download file directly.

---
description: React 19 Compiler & Modern Hooks Architecture - Conventions for React 19: utilize React Compiler automatic memoization, replace boilerplate useMemo/useCallback, adopt useActionState, useOptimistic, and Server Actions.
globs: **/*.tsx, **/*.jsx
alwaysApply: false
author: "Sophie Alpert & React Community (@sophiebits)"
contributor_url: "https://github.com/sophiebits"
verified_by: "agentrules.org"
license: "CC-BY-4.0"
source: "https://agentrules.org/rules/react-19-compiler"
---

# React 19 Compiler & Modern Hooks Architecture

> **Severity**: HIGH | **Category**: frontend
> **Anti-Pattern Warning**: AI wraps every primitive function in useCallback/useMemo out of habit and hallucinates legacy useEffect data fetching.

## System Constraints
You are a modern React 19 engineer. With the React Compiler enabled, stop spraying useMemo and useCallback everywhere unless required for external library referential stability. Prefer useActionState for form handling, useOptimistic for immediate UI feedback, and native async transitions.

## Strict Guidelines
- Do not manually optimize simple calculations with useMemo; let the React 19 compiler optimize rendering.
- Use useActionState instead of manually tracking loading, error, and data states in forms.
- Use useOptimistic for rapid user experience updates before server roundtrips complete.
- Never use useEffect for data fetching in React 19 applications; use Server Components or Suspense-compatible query libraries.
- Ref props are now standard component props; do not write forwardRef in modern React 19 components.

## Bad vs Good Implementations
### Form Mutation: useActionState vs Legacy Boilerplate

#### Bad Antipattern (AI Common Hallucination)
> **Why it fails**: Manual useState boilerplate for loading/error state is fragile and does not integrate with React concurrent transitions.
```tsx
// Legacy React 18: Manual loading, error, and pending state
function ProfileForm() {
  const [loading, setLoading] = useState(false);
  const [error, setError] = useState<string | null>(null);

  const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
    e.preventDefault();
    setLoading(true);
    try {
      await updateProfile(new FormData(e.currentTarget));
    } catch (err: any) {
      setError(err.message);
    } finally {
      setLoading(false);
    }
  };
  return <form onSubmit={handleSubmit}>...</form>;
}
```

#### Production Standard (Correct)
> **Standard**: Uses React 19 native useActionState hook, providing integrated pending state and automatic error handling.
```tsx
// Modern React 19: useActionState
import { useActionState } from "react";
import { updateProfileAction } from "./actions";

export function ProfileForm() {
  const [state, formAction, isPending] = useActionState(updateProfileAction, { error: null });

  return (
    <form action={formAction}>
      <input name="username" required disabled={isPending} />
      {state.error && <p className="text-red-600">{state.error}</p>}
      <button type="submit" disabled={isPending}>
        {isPending ? "Updating..." : "Save Profile"}
      </button>
    </form>
  );
}
```

Recommended MCP Servers (mcp-serverlist.com)

Equip agent with system tools to verify code for this stack.

Recommended Agent Skills (askills.dev)

Ready-to-use executable skill functions tailored to this stack.

Architectural Specification & Invariant Rationale

Architectural Invariant Design: React 19 Compiler & Modern Hooks Architecture

React 19 revolutionizes client state management and performance optimization with the React Compiler (Forget). Manual memoization via `useMemo` and `useCallback` is now largely redundant and can actually hinder the compiler's granular memoization graph. Furthermore, React 19 introduces native async form actions (`useActionState`, `useOptimistic`), replaces `forwardRef` with native ref props, and deprecates `useEffect` for data fetching in favor of Suspense and Server Components.

Framework Paradigm Shift & Drift MechanicsAI coding assistants were trained on tens of thousands of React 16-18 articles advocating defensive memoization (`useCallback` on every click handler). When generating modern React 19 code, LLMs habitually wrap simple calculations in `useMemo` and write 20-line `useState` loading/error boilerplate that should now be handled by a single `useActionState` hook.
Failure Modes & Production Blast Radius

Hazard Analysis: What Breaks Without This Rule

The following failure modes have been cataloged from hundreds of hours of production code reviews where AI assistants produced non-compliant implementations:

Failure ModeAI Symptom (The Anti-Pattern)SeverityProduction Impact & Remedy
Ref Boilerplate via forwardRefAI wraps components in `forwardRef((props, ref) => ...)`Medium
Generates unnecessary wrapper functions and triggers deprecation warnings in React 19.
Pass `ref` directly as a regular component prop: `function Input({ ref, ...props })`.
Redundant useCallback / useMemo SprayingAI wraps every inline event handler in `useCallback` out of defensive habitMedium
Increases bundle overhead, degrades readability, and interferes with React Compiler's automatic SSA optimization.
Only use `useMemo`/`useCallback` when maintaining referential identity for external non-React libraries.
Fragile Manual Form StateAI implements 3 separate `useState` variables for data, isLoading, and errorMessageHigh
Creates race conditions during concurrent form submissions and lacks seamless integration with React transitions.
Use native `useActionState(actionFn, initialState)` which integrates pending states into React concurrent mode.
Architectural Directives in Detail

Step-by-Step Production Directives

Each rule constraint below is injected into the AI agent's system prompt to establish deterministic boundaries:

1

Do not manually optimize simple calculations with useMemo

Do not manually optimize simple calculations with useMemo; let the React 19 compiler optimize rendering.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
2

Use useActionState instead of manually tracking loading, error, and data states in forms.

Use useActionState instead of manually tracking loading, error, and data states in forms.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
3

Use useOptimistic for rapid user experience updates before server roundtrips complete.

Use useOptimistic for rapid user experience updates before server roundtrips complete.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
4

Never use useEffect for data fetching in React 19 applications

Never use useEffect for data fetching in React 19 applications; use Server Components or Suspense-compatible query libraries.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
5

Ref props are now standard component props

Ref props are now standard component props; do not write forwardRef in modern React 19 components.

Rationale:AI models frequently generate unconstrained code here because statistical language distributions lack project-specific architectural context. Mandating this directive ensures that generated code adheres to verified industrial production requirements.
Enforcement:Integrated into the Agent Pack rule file. When Cursor, Claude Code, or Codex processes this prompt, it applies this constraint before emitting syntax.
Technical Questions & Answers

Frequently Asked Technical Questions

Common questions developers face when configuring AI coding assistants for this stack:

Q:Do I still need useMemo and useCallback in React 19?

If the React Compiler is enabled in your build pipeline, you do NOT need manual useMemo or useCallback for internal component rendering. The compiler automatically memoizes values and function references with fine-grained dependency tracking.

Q:What is the replacement for useFormState in React 19?

In React 19, `useFormState` from react-dom was renamed and standardized as `useActionState` in the core `react` package, returning `[state, formAction, isPending]`.

Q:How do refs work in React 19 without forwardRef?

React 19 treats `ref` as a standard prop in function components. You simply accept `ref` in your component's props interface without wrapping it in `forwardRef()`.

Open Specification · CC BY 4.0·Free for Personal, Team & Commercial In-Repo Use

Citation & Open Source Attribution Guidelines

This specification is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0). You are completely free to adapt and share this rule in your workspace. If citing, including in public AI benchmark datasets, or redistributing, attribution to AgentRules.org is required.

Related FRONTEND Rules

View all rules →
frontend
119

SolidStart 1.0 Server Functions & Async Boundaries Production Standard

SolidStart 1.0 relies on the Vinxi bundler to split `server$` closures into independent HTTP POST RPC endpoints. Direct lexical closure over client signals within `server$` scopes or failure to demarcate async boundaries with `<Suspense>` causes silent serialization failures, client-bundle secret leaks, and SSR hydration mismatches. Enforcing strict parameter passing, runtime input validation, and Solid async primitives maintains security and fine-grained reactivity across network boundaries.

frontend
119

Astro 5 Actions & Content Layer Production Standard

Enforces strict type safety and architectural correctness for Astro 5 Server Actions and the zero-waterfall Content Layer API. Prevents runtime contract mismatches, hydration mismatches, and unhandled mutation exceptions across dynamic and prerendered boundaries. Failure to follow these patterns leads to silent data fetching waterfalls, build-time cache corruptions, and unhandled server action exceptions.

frontend
51

Nuxt 4 Nitro Server Engine & Shared Directory Production Standard

Nuxt 4 enforces strict boundary segregation between client UI in the app/ directory, backend endpoints in server/, and universal contracts in shared/. Violating cross-boundary isolation or maintaining module-scoped state in Nitro server handlers causes catastrophic cross-request data corruption and hydration mismatches under concurrent production traffic. Architects must enforce request-isolated H3 event contexts, universal serialization schemas, and strict path-alias boundaries.

1 Rule in Stack

React