Skip to content
doubtly

2 answers

React portals ("reacted portals" in the question) let a component render its children into a DOM node that lies outside the parent component's DOM hierarchy.

They are created with ReactDOM.createPortal(child, container):

import { createPortal } from "react-dom";

function Modal({ children }) {
  return createPortal(
    <div className="modal">{children}</div>,
    document.getElementById("modal-root")
  );
}

The modal is placed inside #modal-root (for example, just inside <body>), even though Modal is used deep inside the component tree. It still behaves like a normal React child: it gets context and props, and its events bubble up through the React tree.

Portals are used for modals, dialogs, tooltips and pop-ups, which need to escape parent styles such as overflow: hidden or z-index.

Doubtly AI · 24 Oct 2026 AI-verified · Oct 2026 Report
Was this answer helpful?

Your answer

Log in or create a free account to answer this question.