@noaignite/react-centra-checkout
Version:
React components and helpers for Centra checkout api
40 lines (39 loc) • 1.06 kB
JavaScript
import { useEffect, useRef } from "react";
import { jsx } from "react/jsx-runtime";
//#region src/internal/HtmlEmbed.tsx
function HtmlEmbed(props) {
const { html, ...other } = props;
const ref = useRef(null);
useEffect(() => {
const createdScripts = [];
const node = ref.current;
if (node && html) {
const scripts = node.getElementsByTagName("script");
Array.from(scripts).forEach((script) => {
if (script.type === "application/json") return;
const scriptEl = document.createElement("script");
if (script.src) scriptEl.src = script.src;
else {
const textNode = document.createTextNode(script.innerHTML);
scriptEl.appendChild(textNode);
}
script.remove();
createdScripts.push(scriptEl);
node.appendChild(scriptEl);
});
}
return () => {
createdScripts.forEach((script) => {
script.remove();
});
};
}, [html]);
return /* @__PURE__ */ jsx("div", {
dangerouslySetInnerHTML: { __html: html },
ref,
...other
});
}
//#endregion
export { HtmlEmbed };
//# sourceMappingURL=HtmlEmbed.js.map