Chuyển đến nội dung
Skillpedia
Website và giao diện (frontend)40k · #7386

react18-legacy-context

Skill này làm gì

Công cụ này giúp cập nhật mã React cũ sang hệ thống mới hơn gọi là “createContext”. Nó hướng dẫn bạn thay thế các phần lỗi thời trong cách chia sẻ dữ liệu giữa các component.

Khi nào nên dùng

  • ✓Khi bạn thấy cảnh báo về “contextTypes” hoặc “getChildContext” trong mã React.
  • ✓Khi cập nhật ứng dụng React lên các phiên bản mới hơn (React 18 trở lên).
  • ✓Trước khi sửa bất kỳ mã nào liên quan đến cách chia sẻ dữ liệu của component React cũ.

Liên kết skill

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

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/github/awesome-copilot/blob/main/skills/react18-legacy-context/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm thế nào để cập nhật hệ thống context cũ của React sang “createContext” mới?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Công cụ xác định nơi dữ liệu được chia sẻ (provider) và nơi dữ liệu được sử dụng (consumer). Sau đó, nó đưa ra kế hoạch từng bước để tạo một tệp context mới và cập nhật cả provider lẫn tất cả consumer sang API mới.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

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
Câu hỏi thường gặp

“contextTypes”, “childContextTypes” và “getChildContext” là gì?

Đây là các cách cũ để chia sẻ dữ liệu giữa các component trong React. Chúng đã được thay thế bằng cách tiếp cận hiện đại và linh hoạt hơn là “createContext”.

Vì sao tôi cần cập nhật tất cả consumer?

Nếu bạn không cập nhật mọi nơi dùng dữ liệu cũ, ứng dụng có thể ngừng hoạt động đúng hoặc hiển thị thông tin sai.

“Provider” và “consumer” là gì?

“Provider” là component cung cấp dữ liệu. “Consumer” là các component nhận và sử dụng dữ liệu đó.

Chi tiết

Mô tả gốc của tác giả

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

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7386
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự