本文へスキップ
Skillpedia
WebサイトとUI(フロントエンド)40k · #7388

react18-string-refs

できること

このツールは、古いReactコードを新しいバージョンに対応させる手助けをします。テキストによる参照(例: `ref='myInput'`)を、より新しい形式(`React.createRef()`)に変換し、コードが正しく動くようにします。

使う場面

  • ✓古いReactプロジェクトを新しいバージョンに更新しているとき。
  • ✓Reactコードで「string refs」に関する警告が表示されたとき。
  • ✓参照を手作業で書き換え始める前。

スキルのリンク

https://github.com/github/awesome-copilot/blob/main/skills/react18-string-refs/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/github/awesome-copilot/blob/main/skills/react18-string-refs/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“Reactの「string refs」を最新の形式に更新するにはどうすればよいですか?”

毎週5つの新しいスキル。1分で読めます。

仕組み

このツールは、Reactコード内でテキストによる参照を使っている箇所を特定します。そのうえで、それらを`React.createRef()`に置き換えるための正確なパターンを示します。これは現在のReactバージョンでの正しい書き方です。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

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
Multiple refs in one component → patterns.md#multiple-refs
Refs in a list / dynamic refs → patterns.md#list-refs
Callback refs (alternative approach) → patterns.md#callback-refs
Ref passed to a child component → patterns.md#forwarded-refs

Scan Command

# 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.

よくある質問

「string refs」とは何ですか?

`ref='myInput'`のように、テキストの名前を使って要素を参照する古いReactの方法です。より安全で現代的な方法に置き換えられています。

なぜ更新する必要があるのですか?

「string refs」は非推奨になっており、将来のReactバージョンでは削除される予定です。更新しておくと、コードが引き続き動作し、新しいバージョンとの互換性も保てます。

`React.createRef()`とは何ですか?

クラスコンポーネントで要素への参照を作成するための、推奨される現代的な方法です。より安全で、意図が明確になります。

詳細

作者による元の説明

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 pat

repo: github/awesome-copilot

人気

GitHubのスター
40k
ランキング
#7388
ライセンス
MIT
更新日
2026/10/15

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル