react19-source-patterns
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseReact 19 Source Migration Patterns
React 19 源码迁移模式
Reference for every source-file migration required for React 19.
React 19 所需的所有源码文件迁移参考。
Quick Reference Table
快速参考表
| Pattern | Action | Reference |
|---|---|---|
| → | See references/api-migrations.md |
| → | See references/api-migrations.md |
| → | Inline fix |
| → direct ref | Inline fix |
| → ref as direct prop | See references/api-migrations.md |
| → ES6 default params | See references/api-migrations.md |
| → | Inline fix add |
| Legacy Context | → | → api-migrations.md#legacy-context |
String refs | → | → api-migrations.md#string-refs |
| Remove | Only if no |
| 模式 | 操作 | 参考 |
|---|---|---|
| → | 见 references/api-migrations.md |
| → | 见 references/api-migrations.md |
| → | 内联修复 |
| → 直接使用ref | 内联修复 |
| → ref作为直接prop传递 | 见 references/api-migrations.md |
| → ES6 默认参数 | 见 references/api-migrations.md |
无参数的 | → | 内联修复,添加 |
| 旧版Context | → | → api-migrations.md#legacy-context |
字符串ref | → | → api-migrations.md#string-refs |
未使用的 | 移除 | 仅当文件中没有使用 |
PropTypes Rule
PropTypes 规则
Do not remove assignments. The 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.
.propTypesprop-typesAdd this comment above any block:
.propTypesjsx
// NOTE: React 19 no longer runs propTypes validation at runtime.
// PropTypes kept for documentation and IDE tooling only.不要移除赋值。包仍然可以作为独立的校验器使用。React 19 仅移除了React包内置的运行时校验能力,这个包本身仍然可用。
.propTypesprop-types在每个代码块上方添加如下注释:
.propTypesjsx
// 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 . It contains the complete patterns including edge cases for with , null vs undefined behavior, and legacy context provider/consumer cross-file migrations.
references/api-migrations.mdforwardRefuseImperativeHandledefaultProps如需获取每个迁移对应的完整代码前后对比,请阅读 。该文档包含完整的迁移模式,包括搭配的边缘情况、的null与undefined行为差异,以及旧版context provider/consumer跨文件迁移等内容。
references/api-migrations.mdforwardRefuseImperativeHandledefaultProps