What are portals in ReactJS?

Technology CommunityCategory: ReactWhat are portals in ReactJS?
VietMX Staff asked 4 years ago

Portal is a recommended way to render children into a DOM node that exists outside the DOM hierarchy of the parent component.

ReactDOM.createPortal(child, container);

The first argument (child) is any renderable React child, such as an element, string, or fragment. The second argument (container) is a DOM element.