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
.claude/rules/react19-no-forwardref.mdWhat 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.mdThe paths frontmatter field limits the files
AGENTS.md
Codex reads AGENTS.md: paste the rule text there
Manually: put the files in place
.cursor/rules/react19-no-forwardref.mdcFrontmatter: description, globs, alwaysApply
Manually: put the files in place
.github/instructions/react19-no-forwardref.instructions.mdThe applyTo field sets which files it applies to
Manually: put the files in place
.devin/rules/react19-no-forwardref.mdManually: put the files in place
.clinerules/react19-no-forwardref.mdStep 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