Skip to main content
rule CX Codex

react19-no-forwardref — Claude Code rule: React 19 API changes

react19-no-forwardref is a Claude Code rule covering React 19 ref and context changes: pass ref as a prop and use use() instead of useContext(). It supports React 19 migrations.

MIT ★ 7,191 updated 2026-10-24

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/rules/react19-no-forwardref.md
Open on GitHub

What react19-no-forwardref does

React 19 simplified ref and context handling. The forwardRef wrapper is no longer needed—just pass ref as a regular prop to a functional component. The use() function replaces useContext() and can be called conditionally, which wasn't allowed before.

The rule includes examples of incorrect and correct code for both patterns. When you describe a component with a ref or work with context, the rule will suggest the current React 19 syntax. Check your components against it if you've just started the upgrade from React 18.

What it helps with

  • Remove forwardRef from components when upgrading to React 19
  • Switch useContext() calls to use() in existing code
  • Pass refs as regular props in function components
  • Call use() conditionally without errors

Example prompts for the agent

  • Rewrite the TextInput component to remove forwardRef for React 19
  • Convert useContext to use() in our app context file
  • Show me the correct way to pass a ref in a React 19 functional component

How to install react19-no-forwardref

Manually: put the files in place

.claude/rules/react19-no-forwardref.md

The paths frontmatter field limits the files

Step by step, with commands for each platform: AGENTS.md vs CLAUDE.md: what they are and which one to use

Questions about react19-no-forwardref

How do I install the react19-no-forwardref rule in Claude Code?

Copy the rule file to your project's .claude/rules/ directory as react19-no-forwardref.md. Claude Code automatically loads rules from this folder on each start.

What does this rule do?

It covers two React 19 changes: ref is now passed as a regular prop without forwardRef, and use() replaces useContext(). The rule shows examples of correct and incorrect patterns.

Is this rule needed for React 18?

No. The rule applies only to React 19 and later. React 18 still uses forwardRef and useContext().

Source text

react19-no-forwardref.md · MIT
---
title: React 19 API Changes
impact: MEDIUM
impactDescription: cleaner component definitions and context usage
tags: react19, refs, context, hooks
---

## React 19 API Changes

> **⚠️ React 19+ only.** Skip this if you're on React 18 or earlier.

In React 19, `ref` is now a regular prop (no `forwardRef` wrapper needed), and `use()` replaces `useContext()`.

**Incorrect (forwardRef in React 19):**

```tsx
const ComposerInput = forwardRef<TextInput, Props>((props, ref) => {
  return <TextInput ref={ref} {...props} />
})
```

**Correct (ref as a regular prop):**

```tsx
function ComposerInput({ ref, ...props }: Props & { ref?: React.Ref<TextInput> }) {
  return <TextInput ref={ref} {...props} />
}
```

**Incorrect (useContext in React 19):**

```tsx
const value = useContext(MyContext)
```

**Correct (use instead of useContext):**

```tsx
const value = use(MyContext)
```

`use()` can also be called conditionally, unlike `useContext()`.

© tech-leads-club · MIT · tech-leads-club/agent-skills

Similar IDE rules

All IDE rules for Frontend and UI →

From the same set130

The whole set →
js-index-maps The js-index-maps rule replaces repeated .find() calls on one key with a Map index. Use it when array lookups happen many times. CX Codex +1 ★ 7,191repo stars rendering-hydration-suppress-warning rendering-hydration-suppress-warning silences hydration warnings where the two renders are meant to differ: timestamps, per-render IDs, dates formatted for the visitor's locale. CX Codex +1 ★ 7,191repo stars bundle-defer-third-party bundle-defer-third-party prevents third-party trackers from inflating the initial bundle. It instructs the assistant to load analytics and monitoring after hydration. CX Codex +1 ★ 7,191repo stars bundle-conditional The bundle-conditional rule recommends loading large modules only when their feature is activated. It applies to lazy-loaded data and browser-only code in SSR builds. CX Codex +1 ★ 7,191repo stars advanced-init-once advanced-init-once prevents running app-wide startup logic inside component useEffect([]) hooks and suggests module-level guards or top-level initialization instead. CX Codex +1 ★ 7,191repo stars rerender-defer-reads The rerender-defer-reads rule keeps callback-only reads of dynamic state out of component subscriptions. Use it when searchParams or localStorage is needed only after an action. CX Codex +1 ★ 7,191repo stars rendering-conditional-render The rendering-conditional-render rule prevents accidental rendering of zeros and NaN in JSX. It enforces explicit ternary operators instead of && checks, so falsy values stay out of the DOM. CX Codex +1 ★ 7,191repo stars server-serialization server-serialization is a Claude Code rule for limiting data passed across React Server/Client boundaries. It applies when client components receive props from server components. CX Codex +1 ★ 7,191repo stars

Project sponsors

Companies that keep this analytics open