React 参考概述
本节提供了有关使用 React 的详细参考文档。如需了解 React 的介绍,请访问 Learn 部分。
🌐 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:
- Hooks - 在你的组件中使用不同的 React 功能。
- 组件 - 你可以在 JSX 中使用的内置组件。
- APIs - 定义组件时有用的 API。
- 指令 - 为与 React 服务器组件兼容的打包工具提供指导。
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:
- Hooks - 用于在浏览器 DOM 环境中运行的 web 应用的 Hooks。
- 组件 - React 支持所有浏览器内置的 HTML 和 SVG 组件。
- API -
react-dom包包含仅在 web 应用中支持的方法。 - 客户端 API -
react-dom/clientAPI 允许你在客户端(浏览器中)渲染 React 组件。 - 服务器 API -
react-dom/serverAPI 让你可以在服务器上将 React 组件渲染为 HTML。 - 静态 API -
react-dom/staticAPI 允许你为 React 组件生成静态 HTML。
React 编译器
🌐 React Compiler
React 编译器是一个构建时优化工具,可以自动记忆你的 React 组件和值:
🌐 The React Compiler is a build-time optimization tool that automatically memoizes your React components and values:
ESLint 插件 React 钩子
🌐 ESLint Plugin React Hooks
React Hooks 的 ESLint 插件 有助于执行 React 的规则:
🌐 The ESLint plugin for React Hooks helps enforce the Rules of React:
- Lints - 每个 lint 的详细文档及示例。
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:
- 组件和 Hook 必须是纯的 – 纯粹性使你的代码更容易理解和调试,并允许 React 自动正确优化你的组件和 Hook。
- React 调用组件和钩子 – React 负责在必要时渲染组件和钩子,以优化用户体验。
- Hooks 规则 – Hooks 使用 JavaScript 函数定义,但它们表示一种特殊类型的可重用 UI 逻辑,并对调用的位置有一定限制。
旧版 API
🌐 Legacy APIs
- 遗留 API - 从
react包导出,但不推荐在新编写的代码中使用。