react18-string-refs — скилл для GitHub Copilot: миграция refs
Помогает заменить строковые refs в классовых компонентах на React.createRef(). Пригодится при переходе на React 18.3.1 или React 19.
npx skills add github/awesome-copilot --skill react18-string-refs -a claude-codeЧто делает react18-string-refs
Скилл описывает замену ref="name" на ref={this.name} и обращений this.refs.name на this.name.current. Он охватывает одиночные и множественные refs, refs в списках, callback refs и передачу refs дочерним компонентам.
Внутри есть команды для поиска строковых refs в src/ и таблица со ссылками на шаблоны миграции. Поиск нужно провести для JSX-атрибутов и обращений this.refs вместе, чтобы сопоставить пары. React 18.3.1 предупреждает о строковых refs, а React 19 их удаляет.
Ставьте скилл, если мигрируете классовые компоненты со строковыми refs; особенно полезны инструкции для refs в списках.
Какие задачи решает
- найти строковые refs в JSX-файлах
- заменить
this.refs.nameнаthis.name.current - перенести несколько refs в одном компоненте
- обработать refs внутри динамического списка
- передать ref дочернему компоненту
Примеры запросов агенту
- Найди все строковые refs в `src/` и составь план миграции.
- Замени `ref="input"` и `this.refs.input` на `React.createRef()` в этом классовом компоненте.
- Перепиши refs в этом списке элементов по шаблону скилла.
Как установить react18-string-refs
1Через Skills CLI (Vercel)
npx skills add github/awesome-copilot --skill react18-string-refs -a claude-code2Вручную: положить файлы
~/.claude/skills/react18-string-refs/SKILL.mdПапка скилла целиком; для одного проекта — .claude/skills/react18-string-refs/
Вручную: положить файлы
.agents/skills/react18-string-refs/SKILL.mdДля всех проектов — ~/.agents/skills/
Вручную: положить файлы
.cursor/skills/react18-string-refs/SKILL.mdCursor читает и .agents/skills/, и .claude/skills/
1Через Skills CLI (Vercel)
npx skills add github/awesome-copilot --skill react18-string-refs2GitHub CLI
gh skill install github/awesome-copilot react18-string-refs3Вручную: положить файлы
.github/skills/react18-string-refs/SKILL.mdКомандой платформы
gemini skills install https://github.com/github/awesome-copilot --path skills/react18-string-refsВручную: положить файлы
.devin/skills/react18-string-refs/SKILL.mdСтарый путь .windsurf/skills/ тоже читается
Claude.ai
Упакуйте папку в zip и загрузите в Settings → Capabilities → Skills
Похожие
Вопросы о react18-string-refs
Как установить react18-string-refs для GitHub Copilot?
Выполните npx skills add github/awesome-copilot --skill react18-string-refs. Также доступна команда gh skill install github/awesome-copilot react18-string-refs.
Что делает react18-string-refs?
Помогает мигрировать строковые refs в классовых компонентах на React.createRef(). Описывает одиночные и множественные refs, списки и передачу refs дочерним компонентам.
Что нужно заменить при миграции строкового ref?
Замените ref="refName" на ref={this.refName}, а this.refs.refName на this.refName.current. Для поиска скилл предлагает команды по src/.
Исходный текст
SKILL.md · MIT
---
name: react18-string-refs
description: 'Provides exact migration patterns for React string refs (ref="name" + this.refs.name) to React.createRef() in class components. Use this skill whenever migrating string ref usage - including single element refs, multiple refs in a component, refs in lists, callback refs, and refs passed to child components. Always use this skill before writing any ref migration code - the multiple-refs-in-list pattern is particularly tricky and this skill prevents the most common mistakes. Use it for React 18.3.1 migration (string refs warn) and React 19 migration (string refs removed).'
---
# React 18 String Refs Migration
String refs (`ref="myInput"` + `this.refs.myInput`) were deprecated in React 16.3, warn in React 18.3.1, and are **removed in React 19**.
## Quick Pattern Map
| Pattern | Reference |
|---|---|
| Single ref on a DOM element | [→ patterns.md#single-ref](references/patterns.md#single-ref) |
| Multiple refs in one component | [→ patterns.md#multiple-refs](references/patterns.md#multiple-refs) |
| Refs in a list / dynamic refs | [→ patterns.md#list-refs](references/patterns.md#list-refs) |
| Callback refs (alternative approach) | [→ patterns.md#callback-refs](references/patterns.md#callback-refs) |
| Ref passed to a child component | [→ patterns.md#forwarded-refs](references/patterns.md#forwarded-refs) |
## Scan Command
```bash
# Find all string ref assignments in JSX
grep -rn 'ref="' src/ --include="*.js" --include="*.jsx" | grep -v "\.test\."
# Find all this.refs accessors
grep -rn "this\.refs\." src/ --include="*.js" --include="*.jsx" | grep -v "\.test\."
```
Both should be migrated together - find the `ref="name"` and the `this.refs.name` accesses for each component as a pair.
## The Migration Rule
Every string ref migrates to `React.createRef()`:
1. Add `refName = React.createRef();` as a class field (or in constructor)
2. Replace `ref="refName"` → `ref={this.refName}` in JSX
3. Replace `this.refs.refName` → `this.refName.current` everywhere
Read `references/patterns.md` for the full before/after for each case.
© github · MIT · github/awesome-copilot