frontAnswerer/src/widget.tsx

26 lines
694 B
TypeScript
Raw Normal View History

import QuizAnswerer from "@/components/QuizAnswerer";
2024-01-20 12:26:28 +00:00
import { Root, createRoot } from "react-dom/client";
let root: Root | undefined = undefined;
const widget = {
create({ selector, quizId, changeFaviconAndTitle = true }: {
2024-01-20 12:26:28 +00:00
selector: string;
quizId: string;
changeFaviconAndTitle: boolean;
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);
root.render(<QuizAnswerer quizId={quizId} changeFaviconAndTitle={changeFaviconAndTitle} />);
2024-01-20 12:26:28 +00:00
},
unmount() {
if (root) root.unmount();
}
};
export default widget;