旧版 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。查看备选方案。¥
Childrenlets you manipulate and transform the JSX received as thechildrenprop. See alternatives. -
cloneElement允许你使用另一个元素作为起点创建一个 React 元素。查看备选方案。¥
cloneElementlets you create a React element using another element as a starting point. See alternatives. -
Component允许你将 React 组件定义为 JavaScript 类。查看备选方案。¥
Componentlets you define a React component as a JavaScript class. See alternatives. -
createElement允许你创建一个 React 元素。通常,你将使用 JSX。¥
createElementlets you create a React element. Typically, you’ll use JSX instead. -
createRef创建一个可以包含任意值的引用对象。查看备选方案。¥
createRefcreates a ref object which can contain arbitrary value. See alternatives. -
forwardRef允许你的组件使用 引用 向父组件公开 DOM 节点。¥
forwardReflets your component expose a DOM node to parent component with a ref. -
isValidElement检查值是否为 React 元素。通常与cloneElement。 一起使用¥
isValidElementchecks whether a value is a React element. Typically used withcloneElement. -
PureComponent与Component, 类似,但它会跳过具有相同属性的重新渲染。查看备选方案。¥
PureComponentis similar toComponent, but it skip re-renders with same props. See alternatives.
已删除的 API
¥Removed APIs
这些 API 在 React 19 中被删除:
¥These APIs were removed in React 19:
-
createFactory:请改用 JSX。¥
createFactory: use JSX instead. -
类组件:
static contextTypes:改用static contextType。¥Class Components:
static contextTypes: usestatic contextTypeinstead. -
类组件:
static childContextTypes:改用static contextType。¥Class Components:
static childContextTypes: usestatic contextTypeinstead. -
类组件:
static getChildContext:改用Context。¥Class Components:
static getChildContext: useContextinstead. -
类组件:
static propTypes:请使用类似 TypeScript 的类型系统。¥Class Components:
static propTypes: use a type system like TypeScript instead.