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
包提供了两个额外的入口:
react-dom/client
包含在客户端(在浏览器中)渲染 React 组件的 API。react-dom/server
包含在服务器上渲染 React 组件的 API。
已移除的 API
这些 API 将在 React 19 中被移除。
findDOMNode
: 查看 替代方案。hydrate
: 使用hydrateRoot
来替代。render
: 使用createRoot
来替代。unmountComponentAtNode
: 使用root.unmount()
来替代。renderToNodeStream
: 使用react-dom/server
API 来替代。renderToStaticNodeStream
: 使用react-dom/server
API 来替代。