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

react19-source-patterns

Skill này làm gì

Hướng dẫn này giúp bạn cập nhật mã React lên phiên bản 19. Nó chỉ cách thay đổi các phần mã cụ thể đã ngừng hoạt động hoặc đã được chuyển trong phiên bản mới.

Khi nào nên dùng

  • ✓Khi cập nhật dự án React lên phiên bản 19.
  • ✓Khi một phần mã React của bạn ngừng hoạt động sau khi cập nhật.
  • ✓Để hiểu những thay đổi cần thiết trong các tệp cụ thể.

Liên kết skill

https://github.com/github/awesome-copilot/blob/main/skills/react19-source-patterns/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/react19-source-patterns/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 ReactDOM.render cho React 19?”

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

Cách hoạt động

AI so sánh mã cũ của bạn với các mẫu chuyển đổi của React 19. Nó đề xuất những thay đổi chính xác cần thiết cho từng phần mã, chẳng hạn thay `ReactDOM.render` bằng `createRoot().render()`.

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 19 Source Migration Patterns

Reference for every source-file migration required for React 19.

Quick Reference Table

Pattern Action Reference
ReactDOM.render(...) → createRoot().render() See references/api-migrations.md
ReactDOM.hydrate(...) → hydrateRoot(...) See references/api-migrations.md
unmountComponentAtNode → root.unmount() Inline fix
ReactDOM.findDOMNode → direct ref Inline fix
forwardRef(...) wrapper → ref as direct prop See references/api-migrations.md
Component.defaultProps = {} → ES6 default params See references/api-migrations.md
useRef() no arg → useRef(null) Inline fix add null
Legacy Context → createContext → api-migrations.md#legacy-context
String refs this.refs.x → createRef() → api-migrations.md#string-refs
import React from 'react' (unused) Remove Only if no React. usage in file

PropTypes Rule

Do not remove .propTypes assignments. The prop-types package still works as a standalone validator. React 19 only removes the built-in runtime checking from the React package the package itself remains valid.

Add this comment above any .propTypes block:

// NOTE: React 19 no longer runs propTypes validation at runtime.
// PropTypes kept for documentation and IDE tooling only.

Read the Reference

For full before/after code for each migration, read references/api-migrations.md. It contains the complete patterns including edge cases for forwardRef with useImperativeHandle, defaultProps null vs undefined behavior, and legacy context provider/consumer cross-file migrations.

Câu hỏi thường gặp

Tôi có cần xóa `.propTypes` không?

Không cần xóa `.propTypes`. Chúng vẫn hoạt động như công cụ kiểm tra dữ liệu, nhưng React 19 không còn tự động chạy chúng. Nên giữ lại để làm tài liệu và hỗ trợ công cụ.

“String refs” là gì?

Đây là cách cũ để tham chiếu phần tử trong React (ví dụ `this.refs.myElement`). React 19 khuyên dùng `createRef()` thay thế.

Còn `useRef()` không có đối số thì sao?

Nếu bạn dùng `useRef()` mà không có giá trị khởi tạo, React 19 yêu cầu thêm `null` làm đối số, tức là `useRef(null)`.

Chi tiết

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

Reference for React 19 source-file migration patterns, including API changes, ref handling, and context updates.

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7390
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ự