React 参考概述

本节提供了使用 React 的详细参考文档。有关 React 的介绍,请访问 学习教程 部分。

¥This section provides detailed reference documentation for working with React. For an introduction to React, please visit the Learn section.

React 参考文档分为几个功能小节:

¥The React reference documentation is broken down into functional subsections:

React

编程式 React 特性:

¥Programmatic React features:

  • 钩子 - 使用组件中不同的 React 功能。

    ¥Hooks - Use different React features from your components.

  • 组件 - 你可以在 JSX 中使用的内置组件。

    ¥Components - Built-in components that you can use in your JSX.

  • API - 对于定义组件很有用的 API。

    ¥APIs - APIs that are useful for defining components.

  • 指令 - 向与 React Server 组件兼容的打包器提供说明。

    ¥Directives - Provide instructions to bundlers compatible with React Server Components.

React DOM

React-dom 包含仅 Web 应用(在浏览器 DOM 环境中运行)支持的功能。本节分为以下几个部分:

¥React-dom contains features that are only supported for web applications (which run in the browser DOM environment). This section is broken into the following:

  • 钩子 - 用于在浏览器 DOM 环境中运行的 Web 应用的钩子。

    ¥Hooks - Hooks for web applications which run in the browser DOM environment.

  • 组件 - React 支持所有浏览器内置的 HTML 和 SVG 组件。

    ¥Components - React supports all of the browser built-in HTML and SVG components.

  • API - react-dom 包包含仅在 Web 应用中支持的方法。

    ¥APIs - The react-dom package contains methods supported only in web applications.

  • 客户端 API - react-dom/client API 允许你在客户端(在浏览器中)渲染 React 组件。

    ¥Client APIs - The react-dom/client APIs let you render React components on the client (in the browser).

  • 服务器 API - react-dom/server API 允许你在服务器上将 React 组件渲染为 HTML。

    ¥Server APIs - The react-dom/server APIs let you render React components to HTML on the server.

React 的规则

¥Rules of React

React 有一些习语(或规则)来说明如何以易于理解的方式表达模式并产生高质量的应用:

¥React has idioms — or rules — for how to express patterns in a way that is easy to understand and yields high-quality applications:

  • 组件和钩子必须是纯的 - Purity 使你的代码更容易理解、调试,并允许 React 自动正确地优化你的组件和钩子。

    ¥Components and Hooks must be pure – Purity makes your code easier to understand, debug, and allows React to automatically optimize your components and hooks correctly.

  • React 调用组件和钩子 - React 负责在必要时渲染组件和钩子以优化用户体验。

    ¥React calls Components and Hooks – React is responsible for rendering components and hooks when necessary to optimize the user experience.

  • 钩子的规则 - 钩子是使用 JavaScript 函数定义的,但它们代表一种特殊类型的可重用 UI 逻辑,并且对调用位置有限制。

    ¥Rules of Hooks – Hooks are defined using JavaScript functions, but they represent a special type of reusable UI logic with restrictions on where they can be called.

旧版 API

¥Legacy APIs

  • 旧版 API - 从 react 包导出,但不建议在新编写的代码中使用。

    ¥Legacy APIs - Exported from the react package, but not recommended for use in newly written code.


React 中文网 - 粤ICP备13048890号