Skillpedia
المواقع والواجهات (frontend)40k · #7386

react18-legacy-context

ما الذي تفعله

تساعد هذه المهارة في تحديث كود React القديم لاستخدام نظام أحدث يسمى « createContext ». وترشدك خطوة بخطوة إلى استبدال الأجزاء القديمة المسؤولة عن مشاركة البيانات بين المكونات.

متى تستخدمها

  • ✓عندما ترى تحذيرات عن « contextTypes » أو « getChildContext » في كود React.
  • ✓عندما تحدّث تطبيق React إلى نسخ أحدث (React 18 أو أعلى).
  • ✓قبل تعديل أي كود يتعلق بمشاركة البيانات القديمة بين مكونات React.

رابط المهارة

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

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/github/awesome-copilot/blob/main/skills/react18-legacy-context/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“كيف أحدّث نظام السياق القديم في React إلى « createContext » الجديد؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تحدد المهارة الأماكن التي تُشارَك فيها البيانات (الموفِّرون) والأماكن التي تُستخدم فيها (المستهلكون). ثم تقدم خطة خطوة بخطوة لإنشاء ملف سياق جديد وتحديث الموفِّرين وكل المستهلكين لاستخدام الواجهة الجديدة.

المحتوى التقني (ملف 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
آخر تحديث
15‏/10‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة