@noaignite/react-centra-checkout
Version:
React components and helpers for Centra checkout api
39 lines • 1.15 kB
JavaScript
// src/internal/HtmlEmbed.tsx
import { useEffect, useRef } from "react";
import { jsx } from "react/jsx-runtime";
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 });
}
export {
HtmlEmbed
};
//# sourceMappingURL=HtmlEmbed.js.map