@zag-js/preact
Version:
The preact wrapper for zag
25 lines (24 loc) • 812 B
JavaScript
// src/portal.tsx
import {
Children,
createPortal,
useLayoutEffect,
useReducer
} from "preact/compat";
var Portal = (props) => {
const { children, container, disabled, getRootNode } = props;
const [, forceUpdate] = useReducer((c) => c + 1, 0);
useLayoutEffect(() => {
forceUpdate({});
}, []);
const isServer = typeof window === "undefined";
if (isServer || disabled) return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
const doc = getRootNode?.().ownerDocument ?? document;
const mountNode = container?.current ?? doc.body;
return /* @__PURE__ */ React.createElement(React.Fragment, null, Children.map(children, (child) => {
return createPortal(/* @__PURE__ */ React.createElement(React.Fragment, null, child), mountNode);
}));
};
export {
Portal
};