跳到正文
Skillpedia
网站与界面(前端)40k · #7390

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/github/awesome-copilot/blob/main/skills/react19-source-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能