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

react18-legacy-context

できること

このツールは、古いReactコードを「createContext」という新しい仕組みを使うように更新する手助けをします。コンポーネント同士でデータを共有する部分のうち、古くなった箇所を置き換える手順を案内します。

使う場面

  • ✓Reactのコードに「contextTypes」や「getChildContext」に関する警告が表示されたとき。
  • ✓Reactアプリケーションを新しいバージョン(React 18以上)に更新するとき。
  • ✓古いコンポーネント間のデータ共有に関わるコードを変更する前。

スキルのリンク

https://github.com/github/awesome-copilot/blob/main/skills/react18-legacy-context/SKILL.md

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

使い方

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

貼り付け用メッセージ

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

AIへの頼み方の例

“Reactの古いコンテキストの仕組みを、新しい「createContext」に更新するにはどうすればよいですか?”

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

仕組み

このツールは、データを提供している場所(プロバイダー)と、それを使っている場所(コンシューマー)を特定します。そのうえで、新しいコンテキストファイルを作成し、プロバイダーとすべてのコンシューマーを新しいAPIを使うように更新するための手順を段階的に示します。

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

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

React 18 Legacy Context Migration

Legacy context (contextTypes, childContextTypes, getChildContext) was deprecated in React 16.3 and warns in React 18.3.1. It is removed in React 19.

This Is Always a Cross-File Migration

Unlike most other migrations that touch one file at a time, context migration requires coordinating:

  1. Create the context object (usually a new file)
  2. Update the provider component
  3. Update every consumer component

Missing any consumer leaves the app broken - it will read from the wrong context or get undefined.

Migration Steps (Always Follow This Order)

Step 1: Find the provider (childContextTypes + getChildContext)
Step 2: Find ALL consumers (contextTypes)
Step 3: Create the context file
Step 4: Update the provider
Step 5: Update each consumer (class components → contextType, function components → useContext)
Step 6: Verify - run the app, check no legacy context warnings remain

Scan Commands

# Find all providers
grep -rn "childContextTypes\|getChildContext" src/ --include="*.js" --include="*.jsx" | grep -v "\.test\."

# Find all consumers
grep -rn "contextTypes\s*=" src/ --include="*.js" --include="*.jsx" | grep -v "\.test\."

# Find this.context usage (may be legacy or modern - check which)
grep -rn "this\.context\." src/ --include="*.js" --include="*.jsx" | grep -v "\.test\."

Reference Files

  • references/single-context.md - complete migration for one context (theme, auth, etc.) with provider + class consumer + function consumer
  • references/multi-context.md - apps with multiple legacy contexts (nested providers, multiple consumers of different contexts)
  • references/context-file-template.md - the standard file structure for a new context module
よくある質問

「contextTypes」「childContextTypes」「getChildContext」とは何ですか?

Reactでコンポーネント間のデータを共有する古い方法です。より現代的で柔軟な「createContext」という方法に置き換えられています。

なぜすべてのコンシューマーを更新する必要があるのですか?

古いデータを使っている箇所をすべて更新しないと、アプリケーションが正しく動作しなくなったり、誤った情報を表示したりする可能性があるためです。

プロバイダーとコンシューマーとは何ですか?

「プロバイダー」はデータを提供するコンポーネントです。「コンシューマー」はそのデータを受け取って使うコンポーネントです。

詳細

作者による元の説明

Provides the complete migration pattern for React legacy context API (contextTypes, childContextTypes, getChildContext) to the modern createContext API. Use this skill whenever migrating legacy context in class components - this is always a cross-file migration requiring the provider AND all consumers to be updated together. Use it before touching any contextTypes or childContextTypes code, becaus

repo: github/awesome-copilot

人気

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

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

0

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

コメント

  • …

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

似ているスキル