fui-fancyui
Version:
FancyUI Libary
21 lines (20 loc) • 563 B
JavaScript
"use client";
import { useState as c, useEffect as l, createElement as i } from "react";
import f from "react-dom";
function d({ children: e, appendToID: t, WrapperComponent: n }) {
const [r, o] = c(null);
l(() => {
const u = t ? document.getElementById(t) : document.body;
if (!u)
throw new Error(`Could not find container with ID: "${t || "undefined"}"}"`);
return o(u), () => {
o(null);
};
}, [t, e]);
const a = n ? i(n, {}, e) : e;
return r ? f.createPortal(a, r) : null;
}
export {
d as FancyPortal,
d as default
};