react18-string-refs

Migrates React string refs to React.createRef() patterns in class components.

38.5k|4.9k|Updated Jun 11, 2025
One-click install
npx skills add https://github.com/github/awesome-copilot --skill react18-string-refs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: react18-string-refs
Source: https://github.com/github/awesome-copilot/tree/main/skills/react18-string-refs
Command: npx skills add https://github.com/github/awesome-copilot --skill react18-string-refs

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

React string refs (ref="name" + this.refs.name) warn in React 18.3.1 and are removed entirely in React 19, breaking legacy class components during upgrades. This Skill provides exact before/after migration patterns so every string ref is converted correctly to React.createRef() without common mistakes.

Core Features & Use Cases

  • Complete Pattern Coverage: Provides before/after code for single DOM refs, multiple refs in one component, refs in dynamic lists, callback refs, and refs passed to child components via forwardRef.
  • Scan Commands: Includes grep commands to locate all ref="name" assignments and this.refs accessors so paired usages are migrated together.
  • Tricky Case Handling: Documents the Map-based dynamic ref pattern for lists and warns against inline callback refs that cause ref flicker.
  • Use Case: When upgrading a codebase to React 18.3.1 or React 19, use this Skill to systematically convert every string ref in class components, including the difficult refs-in-a-map case.

Quick Start

Ask the AI to migrate all string refs in your React class components to React.createRef() using this skill's patterns.

Frequently Asked Questions about react18-string-refs

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

FAQPage Schema
How do I migrate React string refs to createRef?

Add a class field like myRef = React.createRef(), replace ref="myRef" with ref={this.myRef} in JSX, and change this.refs.myRef to this.myRef.current everywhere. Migrate the JSX assignment and the this.refs accessors together as a pair.

How to convert string refs inside a map or list in React?

Store refs in a Map keyed by item id, creating each ref lazily with React.createRef(). Alternatively use a callback ref that stores DOM nodes directly in an object, noting that callback refs hold the element itself, not a .current wrapper.

Are string refs removed in React 19?

Yes, string refs were deprecated in React 16.3, produce warnings in React 18.3.1, and are removed in React 19. All ref="name" and this.refs.name usage must be migrated to createRef or callback refs before upgrading.

When should I use callback refs instead of createRef?

Use createRef for a fixed number of refs known at component definition time. Use callback refs for dynamic lists, when you need to react to attach/detach, or when the ref target may change. Avoid inline callback refs since they recreate the function every render.

How do I pass a ref to a child component in React 18 vs React 19?

In React 18, wrap the child in forwardRef so it can receive and attach the ref to a DOM node. In React 19, ref is passed as a regular prop and forwardRef is no longer needed.