@daimo/pay
Version:
Seamless crypto payments. Onboard users from any chain, any coin into your app with one click.
31 lines (28 loc) • 952 B
JavaScript
import { useRef, useState, useEffect } from 'react';
import { createPortal } from 'react-dom';
import packageJson from '../../../../package.json.js';
const Portal = (props) => {
props = {
selector: "__DAIMOPAY__",
...props
};
const { selector, children } = props;
const ref = useRef(null);
const [mounted, setMounted] = useState(false);
useEffect(() => {
const selectorPrefixed = "#" + selector.replace(/^#/, "");
ref.current = document.querySelector(selectorPrefixed);
if (!ref.current) {
const div = document.createElement("div");
div.setAttribute("id", selector);
div.setAttribute("data-daimopay", `${packageJson.version}`);
document.body.appendChild(div);
ref.current = div;
}
setMounted(true);
}, [selector]);
if (!ref.current) return null;
return mounted ? createPortal(children, ref.current) : null;
};
export { Portal as default };
//# sourceMappingURL=index.js.map