UNPKG

@vectara/vectara-ui

Version:

Vectara's design system, codified as a React and Sass component library

16 lines (15 loc) 648 B
import { useEffect, useRef } from "react"; import { createPortal } from "react-dom"; export const VuiPortal = ({ children }) => { // Initialize ref synchronously during the first render, ensuring portalRef.current // is immediately available for createPortal. const portalRef = useRef(document.createElement("div")); useEffect(() => { document.body.appendChild(portalRef.current); return () => { var _a; (_a = portalRef.current.parentNode) === null || _a === void 0 ? void 0 : _a.removeChild(portalRef.current); }; }, []); return createPortal(children, portalRef.current); };