Langsung ke konten
Skillpedia
Website & UI (frontend)40k · #7386

react18-legacy-context

Fungsinya

Alat ini membantu Anda memperbarui kode React lama agar menggunakan sistem baru bernama 'createContext'. Alat ini memandu Anda mengganti bagian kode yang sudah usang dan menangani pembagian data antar komponen.

Kapan dipakai

  • ✓Saat Anda melihat peringatan tentang 'contextTypes' atau 'getChildContext' di kode React Anda.
  • ✓Saat memperbarui aplikasi React ke versi yang lebih baru (React 18 atau lebih tinggi).
  • ✓Sebelum mengubah kode apa pun yang terkait dengan pembagian data pada komponen React versi lama.

Link skill

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

Salin lalu tempelkan ke AI Anda (Claude, ChatGPT, atau Cursor) dan minta AI mengikuti instruksinya.

Cara pakai

Cara paling mudah: salin pesan ini dan tempelkan ke AI Anda. AI akan membaca skill dan mengikuti instruksinya.

Pesan siap tempel

Gunakan skill ini untuk membantu saya: https://github.com/github/awesome-copilot/blob/main/skills/react18-legacy-context/SKILL.md Baca file SKILL.md di link tersebut dan ikuti instruksinya untuk tugas saya.
Mau AI Anda menemukan skill seperti ini sendiri?Pasang MCP Skillpedia gratis: cukup satu baris, dan AI mencari di antara 15.000+ skill sebelum tiap tugas.Pasang dalam 1 menit →

Contoh permintaan ke AI

“Bagaimana cara memperbarui sistem context lama di React menjadi 'createContext' yang baru?”

5 skill baru setiap minggu. 1 menit baca.

Cara kerjanya

Alat ini mengidentifikasi tempat data dibagikan (provider) dan tempat data digunakan (consumer). Setelah itu, alat ini memberikan rencana langkah demi langkah untuk membuat file context baru dan memperbarui provider serta semua consumer agar menggunakan API yang baru.

Konten teknis (SKILL.md asli)

Teks asli dari pembuat, dalam bahasa Inggris, langsung dari 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
Pertanyaan umum

Apa itu 'contextTypes', 'childContextTypes', dan 'getChildContext'?

Ini adalah cara lama di React untuk membagikan data antar komponen. Cara tersebut sudah digantikan oleh pendekatan yang lebih modern dan fleksibel, yaitu 'createContext'.

Mengapa saya perlu memperbarui semua consumer?

Jika Anda tidak memperbarui setiap tempat yang menggunakan data lama, aplikasi Anda bisa berhenti berfungsi dengan benar atau menampilkan informasi yang salah.

Apa itu 'provider' dan 'consumer'?

'Provider' adalah komponen yang menyediakan data. 'Consumer' adalah komponen yang menerima dan menggunakan data tersebut.

Detail

Deskripsi asli dari pembuat

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

Popularitas

Bintang GitHub
40k
Peringkat
#7386
Lisensi
MIT
Diperbarui
15/10/2026

Apakah skill ini berguna?

0

Masuk untuk memberi suara.

Komentar

  • …

Skill lain dari repositori ini

Skill serupa