React DOM API

react-dom 包包含的方法仅支持 Web 应用(在浏览器 DOM 环境中运行)。它们不支持 React Native。

🌐 The react-dom package contains methods that are only supported for the web applications (which run in the browser DOM environment). They are not supported for React Native.


API

🌐 APIs

这些 API 可以从你的组件中导入。它们很少被使用:

🌐 These APIs can be imported from your components. They are rarely used:

  • [createPortal](/reference/react-dom/createPortal) 让你在 DOM 树的不同部分渲染子组件。
  • flushSync 让你强制 React 刷新状态更新并同步更新 DOM。

资源预加载 API

🌐 Resource Preloading APIs

这些 API 可用于在你知道需要时立即预加载脚本、样式表和字体等资源,例如在导航到将使用资源的另一个页面之前,从而使应用运行得更快。

🌐 These APIs can be used to make apps faster by pre-loading resources such as scripts, stylesheets, and fonts as soon as you know you need them, for example before navigating to another page where the resources will be used.

基于 React 的框架 通常会为你处理资源加载,因此你可能不需要自己调用这些 API。有关详细信息,请查阅你所使用框架的文档。

  • prefetchDNS 允许你预取你预计将要连接的 DNS 域名的 IP 地址。
  • preconnect 让你连接到你预期会请求资源的服务器,即使你还不知道将需要哪些资源。
  • preload 允许你获取你期望使用的样式表、字体、图片或外部脚本。
  • [preloadModule](/reference/react-dom/preloadModule) 让你获取一个你预计会使用的 ESM 模块。
  • preinit 让你获取并评估外部脚本,或获取并插入样式表。
  • preinitModule 允许你获取和评估一个 ESM 模块。

入口点

🌐 Entry points

react-dom 包提供了两个额外的入口点:

🌐 The react-dom package provides two additional entry points:


已删除的 API

🌐 Removed APIs

这些 API 在 React 19 中被删除:

🌐 These APIs were removed in React 19: