旧版 React API
这些 API 是从 react 包导出的,但不建议在新编写的代码中使用。请参阅链接的各个 API 页面以获取建议的替代方案。
🌐 These APIs are exported from the react package, but they are not recommended for use in newly written code. See the linked individual API pages for the suggested alternatives.
旧版 API
🌐 Legacy APIs
Children让你操作和转换作为children属性接收的 JSX。查看替代方案。cloneElement让你可以使用另一个元素作为起点来创建一个 React 元素。查看替代方案。Component让你可以将 React 组件定义为一个 JavaScript 类。查看替代方案。createElement让你创建一个 React 元素。通常,你会使用 JSX。createRef创建一个可以包含任意值的 ref 对象。查看替代方案。forwardRef允许你的组件通过 ref. 将 DOM 节点暴露给父组件isValidElement检查一个值是否为 React 元素。通常与cloneElement一起使用。PureComponent类似于Component,但在 props 相同的情况下会跳过重新渲染。查看替代方案。
已删除的 API
🌐 Removed APIs
这些 API 在 React 19 中被删除:
🌐 These APIs were removed in React 19:
createFactory:改用 JSX。- 类组件:
static contextTypes:请使用static contextType替代。 - 类组件:
static childContextTypes:请使用static contextType替代。 - 类组件:
static getChildContext:请使用Context替代。 - 类组件:
static propTypes:改用像 TypeScript 这样的类型系统。 - 类组件:
this.refs:请使用createRef替代。