frontAnswerer/src/widgets/container/ContainerWidget.tsx

30 lines
708 B
TypeScript
Raw Normal View History

2024-04-24 15:56:11 +00:00
import QuizAnswerer from "@/components/QuizAnswerer";
import { Root, createRoot } from "react-dom/client";
export class ContainerWidget {
root: Root | undefined;
constructor({ selector, quizId }: {
quizId: string;
selector: string;
}) {
const element = document.querySelector(selector);
2024-04-24 15:56:11 +00:00
if (!element) throw new Error("Element for widget doesn't exist");
this.root = createRoot(element);
this.root.render(
<QuizAnswerer
quizId={quizId}
changeFaviconAndTitle={false}
disableGlobalCss
/>
);
}
destroy() {
if (this.root) this.root.unmount();
}
}