UNPKG

@appbuckets/react-ui-core

Version:

Core utilities built for AppBuckets React UI Framework

40 lines (37 loc) 1.12 kB
import * as React from 'react'; import { createPortal } from 'react-dom'; import Ref from '../Ref/Ref.js'; var PortalInner = function (props) { var children = props.children, innerRef = props.innerRef, mountNode = props.mountNode, userDefinedOnMountHandler = props.onMount, userDefinedOnUnmountHandler = props.onUnmount; // ---- // Call Lifecycle Event // ---- React.useEffect( function () { /** Call onMount */ if (typeof userDefinedOnMountHandler === 'function') { userDefinedOnMountHandler(); } /** Call onUnmount */ return function () { if (typeof userDefinedOnUnmountHandler === 'function') { userDefinedOnUnmountHandler(); } }; }, // This hook is limited to be used as an internal handler // to fire onMount / onUnmount handler. // eslint-disable-next-line react-hooks/exhaustive-deps [] ); return createPortal( React.createElement(Ref, { innerRef: innerRef }, children), mountNode || document.body ); }; PortalInner.displayName = 'PortalInner'; export { PortalInner as default };