UNPKG

figform

Version:
30 lines 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FigForm = FigForm; var tslib_1 = require("tslib"); var React = tslib_1.__importStar(require("react")); var options_1 = require("./options"); var script_1 = require("./script"); function FigForm(_a) { var id = _a.id, options = tslib_1.__rest(_a, ["id"]); var mountRef = React.useRef(null); var parentRef = React.useRef(null); React.useLayoutEffect(function () { if (mountRef.current !== null && mountRef.current.parentElement !== null) { parentRef.current = mountRef.current.parentElement; mountRef.current.remove(); } }, []); React.useEffect(function () { var resolvedOptions = (0, options_1.resolveOptions)(options, parentRef.current); var url = "".concat(resolvedOptions.baseUrl, "/f/").concat(id); if (!(0, script_1.existsScript)(id, url)) { (0, script_1.createScript)(url, resolvedOptions.parent); } return function () { (0, script_1.unmountScript)(url); }; }, [id, options]); return React.createElement("span", { id: "figform-".concat(id), ref: mountRef, style: { display: "none" } }); } //# sourceMappingURL=react.js.map