旧版 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。查看备选方案。¥
Children
lets you manipulate and transform the JSX received as thechildren
prop. See alternatives. -
cloneElement
允许你使用另一个元素作为起点创建一个 React 元素。查看备选方案。¥
cloneElement
lets you create a React element using another element as a starting point. See alternatives. -
Component
允许你将 React 组件定义为 JavaScript 类。查看备选方案。¥
Component
lets you define a React component as a JavaScript class. See alternatives. -
createElement
允许你创建一个 React 元素。通常,你将使用 JSX。¥
createElement
lets you create a React element. Typically, you’ll use JSX instead. -
createRef
创建一个可以包含任意值的引用对象。查看备选方案。¥
createRef
creates a ref object which can contain arbitrary value. See alternatives. -
forwardRef
允许你的组件使用 引用 向父组件公开 DOM 节点。¥
forwardRef
lets your component expose a DOM node to parent component with a ref. -
isValidElement
检查值是否为 React 元素。通常与cloneElement
。 一起使用¥
isValidElement
checks whether a value is a React element. Typically used withcloneElement
. -
PureComponent
与Component
, 类似,但它会跳过具有相同属性的重新渲染。查看备选方案。¥
PureComponent
is 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 contextType
instead. -
类组件:
static childContextTypes
:改用static contextType
。¥Class Components:
static childContextTypes
: usestatic contextType
instead. -
类组件:
static getChildContext
:改用Context.Provider
。¥Class Components:
static getChildContext
: useContext.Provider
instead. -
类组件:
static propTypes
:请使用类似 TypeScript 的类型系统。¥Class Components:
static propTypes
: use a type system like TypeScript instead.