30 lines
709 B
TypeScript
30 lines
709 B
TypeScript
![]() |
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.getElementById(selector);
|
||
|
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();
|
||
|
}
|
||
|
}
|