25 lines
514 B
TypeScript
25 lines
514 B
TypeScript
![]() |
import { Root, createRoot } from "react-dom/client";
|
||
|
import App from "./App";
|
||
|
import "./index.css";
|
||
|
|
||
|
|
||
|
let root: Root | undefined = undefined;
|
||
|
|
||
|
const widget = {
|
||
|
create({ selector }: {
|
||
|
selector: string;
|
||
|
}) {
|
||
|
const element = document.getElementById(selector);
|
||
|
if (!element) throw new Error("Element for widget doesn't exist");
|
||
|
|
||
|
root = createRoot(element);
|
||
|
|
||
|
root.render(<App />);
|
||
|
},
|
||
|
unmount() {
|
||
|
if (root) root.unmount();
|
||
|
}
|
||
|
};
|
||
|
|
||
|
export default widget;
|