UNPKG

@nex-ui/react

Version:

🎉 A beautiful, modern, and reliable React component library.

23 lines (20 loc) • 601 B
"use client"; import { createPortal } from 'react-dom'; import { useState, useEffect } from 'react'; import { isFunction } from '@nex-ui/utils'; const Portal = (props)=>{ const { children, container } = props; const [mountNode, setMountNode] = useState(null); useEffect(()=>{ let node = container; if (isFunction(node)) { node = node(); } setMountNode(node || document.body); }, [ container ]); return mountNode ? /*#__PURE__*/ createPortal(children, mountNode) : null; }; Portal.displayName = 'Portal'; export { Portal };