React DOM API

react-dom 包包含一些仅支持在浏览器 DOM 环境下运行的方法,不支持在 React Native 中使用。


API

这些 API 可以在你的组件中导入,但是很少使用:

  • createPortal 允许你将子组件渲染到 DOM 树的不同位置。
  • flushSync 允许你强制 React 同步刷新状态并更新 DOM。

Resource Preloading APIs

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-based frameworks frequently handle resource loading for you, so you might not have to call these APIs yourself. Consult your framework’s documentation for details.

  • prefetchDNS lets you prefetch the IP address of a DNS domain name that you expect to connect to.
  • preconnect lets you connect to a server you expect to request resources from, even if you don’t know what resources you’ll need yet.
  • preload lets you fetch a stylesheet, font, image, or external script that you expect to use.
  • preloadModule lets you fetch an ESM module that you expect to use.
  • preinit lets you fetch and evaluate an external script or fetch and insert a stylesheet.
  • preinitModule lets you fetch and evaluate an ESM module.

入口

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


已移除的 API

这些 API 将在 React 19 中被移除。