react19-source-patterns
Reference for React 19 source-file migration patterns, including API changes, ref handling, and context updates.
它会碰到什么
这一栏是扫描器报的事实,不是结论。命中多不等于有毒(安全工具、规则库、示例脚本本来就会包含危险写法),命中少也不等于干净。它和你手上的凭据、文件、网络有什么关系,需要你自己看。
技能内容
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](references/api-migrations.md#legacy-context) |
| String refs this.refs.x | → createRef() | [→ api-migrations.md#string-refs](references/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.
想直接用这个技能?
本站把开放许可(MIT / Apache 等)的技能按仓库打包整理到网盘,点一下转存到你自己的网盘,不用一个个从 GitHub 拉。许可未声明的技能只给原始仓库链接,不打包。