frontAnswerer/src/widget.tsx
nflnkr fb3d46110f split widget and default App components
use router in default App for retrieving quizId from url
add QuizIdContext
2024-02-01 16:18:16 +03:00

36 lines
727 B
TypeScript

import WidgetApp from "./WidgetApp";
import { Root, createRoot } from "react-dom/client";
let root: Root | undefined = undefined;
const widget = {
create({ selector, quizId }: {
selector: string;
quizId: string;
}) {
const element = document.getElementById(selector);
if (!element) throw new Error("Element for widget doesn't exist");
root = createRoot(element);
root.render(<WidgetApp quizId={quizId} />);
},
unmount() {
if (root) root.unmount();
}
};
export default widget;
/*
<script type="module">
import widget from ".../widget.js";
widget.create({
selector: "widget-container",
quizId: "...",
})
</script>
*/