Portal allows you to render children into a DOM node. CreatePortalmethod is used for it.
2 answers
codelikepro
· 19 Aug 2022
Report
Was this answer helpful?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
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?
Thanks for the feedback.
Sign up free to save answers and ask your own doubts
Your answer
Log in or create a free account to answer this question.