2024-01-20 12:26:28 +00:00
|
|
|
import { Root, createRoot } from "react-dom/client";
|
2024-02-14 11:03:35 +00:00
|
|
|
import WidgetApp from "./WidgetApp";
|
2024-01-20 12:26:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
let root: Root | undefined = undefined;
|
|
|
|
|
|
|
|
const widget = {
|
2024-01-31 14:39:50 +00:00
|
|
|
create({ selector, quizId }: {
|
2024-01-20 12:26:28 +00:00
|
|
|
selector: string;
|
2024-01-31 14:39:50 +00:00
|
|
|
quizId: string;
|
2024-01-20 12:26:28 +00:00
|
|
|
}) {
|
|
|
|
const element = document.getElementById(selector);
|
|
|
|
if (!element) throw new Error("Element for widget doesn't exist");
|
|
|
|
|
|
|
|
root = createRoot(element);
|
|
|
|
|
2024-02-14 11:03:35 +00:00
|
|
|
root.render(<WidgetApp quizId={quizId} />);
|
2024-01-20 12:26:28 +00:00
|
|
|
},
|
|
|
|
unmount() {
|
|
|
|
if (root) root.unmount();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default widget;
|