API React DOM

package react-dom berisi method yang hanya didukung untuk aplikasi web (yang berjalan di lingkungan DOM peramban). Mereka tidak didukung untuk React Native.


API

API ini dapat di import dari komponen. Namun, jarang digunakan:

  • createPortal memungkinkan Anda untuk me-render child component ke dalam bagian DOM tree yang berbeda.
  • flushSync memungkinkan Anda untuk memaksa React untuk segera mengeksekusi pembaruan state dan memperbarui DOM secara sinkron.

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.

Titik masuk

Package react-dom menyediakan dua titik masuk tambahan:

  • react-dom/client berisi API untuk me-render komponen React di sisi klien (di dalam peramban).
  • react-dom/server berisi API untuk me-render komponen React di sisi server.

API Dihapus

API ini telah dihapus di React 19: