@noaignite/react-centra-checkout
Version:
React components and helpers for Centra checkout api
41 lines (40 loc) • 1.19 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
let react = require("react");
let react_jsx_runtime = require("react/jsx-runtime");
//#region src/internal/HtmlEmbed.tsx
function HtmlEmbed(props) {
const { html, ...other } = props;
const ref = (0, react.useRef)(null);
(0, react.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__ */ (0, react_jsx_runtime.jsx)("div", {
dangerouslySetInnerHTML: { __html: html },
ref,
...other
});
}
//#endregion
exports.HtmlEmbed = HtmlEmbed;
//# sourceMappingURL=HtmlEmbed.cjs.map