migrating-from-forwardref

Migrate deprecated forwardRef usage to the ref-as-prop pattern in React 19.

Updated Nov 21, 2025
One-click install
npx skills add https://github.com/djankies/claude-configs --skill migrating-from-forwardref
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: migrating-from-forwardref
Source: https://github.com/djankies/claude-configs/tree/main/react-19/concerns/hooks/skills/migrating-from-forwardref
Command: npx skills add https://github.com/djankies/claude-configs --skill migrating-from-forwardref

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

The forwardRef API is deprecated in React 19, requiring migration to a new, simpler ref-as-prop pattern. This Skill guides you through updating your components and TypeScript types to the modern approach.

Core Features & Use Cases

  • Simpler API: Learn to pass ref as a regular prop, eliminating the need for the forwardRef wrapper.
  • Better TypeScript: Understand how to correctly type components that accept refs in React 19, improving type inference.
  • Less Boilerplate: Reduce code by removing unnecessary imports and wrapper functions.
  • useImperativeHandle Compatibility: Ensure useImperativeHandle continues to work correctly with the new pattern.
  • Use Case: Migrate a CustomInput component from using forwardRef to the new ref-as-prop pattern, ensuring its ref functionality (e.g., focus(), clear()) remains intact and types are updated.

Quick Start

Refactor the Button component in src/components/Button.js to remove forwardRef and accept ref as a regular prop.

Frequently Asked Questions about migrating-from-forwardref

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate forwardRef to React 19's ref-as-prop pattern?

React 19 deprecates forwardRef in favor of passing ref as a regular prop. Convert your component to accept ref as a prop parameter, remove the forwardRef wrapper and React.forwardRef import, and update TypeScript types to include ref in the component's prop interface. This simplifies your component definition while maintaining ref functionality.

Why is forwardRef deprecated in React 19?

forwardRef was a workaround to pass refs through components that normally wouldn't accept them. React 19 treats ref as a regular prop, eliminating the need for the wrapper. This reduces boilerplate, improves TypeScript inference, and makes components simpler and more intuitive.

How do I update TypeScript types when removing forwardRef?

Add ref to your component's prop interface using React.RefObject or React.Ref with the appropriate element or imperative handle type. Remove ForwardRefRenderFunction or React.forwardRef from type definitions. This ensures proper type checking and IDE autocomplete for ref-accepting components.

Does useImperativeHandle work with React 19's ref-as-prop pattern?

Yes, useImperativeHandle works identically with the ref-as-prop pattern. Define your imperative handle inside useImperativeHandle, attach it to the ref prop, and the ref will expose those methods. No changes to your useImperativeHandle logic are needed.

What's the difference between forwardRef and the new ref-as-prop approach?

forwardRef wraps a component and requires a special second parameter to access refs; ref-as-prop treats ref like any other prop. The new approach is simpler, requires less code, integrates better with TypeScript, and is the recommended React 19 pattern for components that need ref access.

Can I use ref-as-prop with custom imperative handles?

Yes, ref-as-prop fully supports custom imperative handles via useImperativeHandle. Declare your ref prop with type matching your handle shape, attach it in useImperativeHandle, and consumers can call those exposed methods. This works for DOM refs and custom object refs alike.