createPortal

ReactPortal createPortal(

  1. ReactElement children,
  2. JSObject container
)

Renders a React element into a portal, allowing it to appear in a different part of the DOM tree.

Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.

Example:

final modalRoot = Document.getElementById('modal-root')!;
final modal = createPortal(
  div(children: [pEl('Modal content')]),
  modalRoot,
);

Implementation

ReactPortal createPortal(ReactElement children, JSObject container) =>
    ReactPortal.fromJs(_reactDomCreatePortal(children, container));