react19-source-patterns
它能做什么
这份指南可以帮你更新 React 代码以适配 19 版本。它会告诉你如何修改那些在新版本中已经失效或发生变化的代码部分。
适用场景
- ✓当你要把 React 项目升级到 19 版本时。
- ✓当你的某部分 React 代码在升级后无法正常工作时。
- ✓为了了解特定文件中需要做出的必要修改。
技能链接
https://github.com/github/awesome-copilot/blob/main/skills/react19-source-patterns/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我该如何为 React 19 更新 `ReactDOM.render`?”
每周 5 个新技能,1 分钟读完。
工作原理
AI 会将你的旧代码与 React 19 的迁移模式进行对比,针对每个代码部分给出需要做的具体修改建议,比如把 `ReactDOM.render` 替换为 `createRoot().render()`。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
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.
常见问题
我需要删除 `.propTypes` 吗?
不需要。`.propTypes` 仍然可以作为验证器使用,只是 React 19 不再自动运行它们。保留它们对文档和开发工具仍然有帮助。
什么是“字符串 refs”(String refs)?
这是 React 中一种旧的引用元素方式,比如 `this.refs.myElement`。React 19 建议改用 `createRef()`。
没有参数的 `useRef()` 怎么办?
如果你使用 `useRef()` 时没有传入初始值,React 19 会要求你添加 `null` 作为参数,写成 `useRef(null)`。
详情
作者的原始描述
Reference for React 19 source-file migration patterns, including API changes, ref handling, and context updates.
repo: github/awesome-copilot
热度
- GitHub 星标
- 40k
- 排名
- #7390
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …
同一仓库的更多技能
acquire-codebase-knowledge
40k帮你的智能体理解并编写现有代码项目的文档。它有助于新成员快速上手,或者快速了解项目架构。
acreadiness-assess
40k让你的智能体评估一个项目对 AI 的准备程度,并生成报告。它有助于了解项目在使用 AI 工具方面的准备情况。
acreadiness-generate-instructions
40k帮你的智能体根据评估结果编写 AI 工具的指令文件。它有助于改善 AI 与代码的交互方式,并弥补已发现的不足。
acreadiness-policy
40k让你的智能体协助制定或应用 AI 项目评估的政策。它有助于规范项目的评估方式,并确保合规。