@atlaskit/portal
Version:
A wrapper for rendering components in React portals.
22 lines (21 loc) • 874 B
JavaScript
import { useEffect, useMemo } from 'react';
import { createPortal } from 'react-dom';
import { appendPortalContainerIfNotAppended, createContainer, removePortalContainer } from '../utils/portal-dom-utils';
export default function InternalPortal(props) {
var zIndex = props.zIndex,
children = props.children;
var container = useMemo(function () {
return createContainer(zIndex);
}, [zIndex]);
// This is in the render method instead of useEffect so that
// the portal will be added to the DOM before the children render.
// For any further changes, ensure that the container does not have a
// parent besides the portal parent.
appendPortalContainerIfNotAppended(container);
useEffect(function () {
return function () {
removePortalContainer(container);
};
}, [container]);
return /*#__PURE__*/createPortal(children, container);
}