|
@@ -13,16 +13,18 @@ export const useUnmountComponent = () => {
|
|
|
};
|
|
|
|
|
|
export function mountComponent(RootComponent: Component, rootProps?: Record<string, unknown> | null | undefined) {
|
|
|
- const app = createApp(RootComponent, rootProps);
|
|
|
+ const app = createApp(RootComponent, { ...rootProps, unmount });
|
|
|
const root = document.createElement("div");
|
|
|
|
|
|
+ function unmount() {
|
|
|
+ app.unmount();
|
|
|
+ document.body.removeChild(root);
|
|
|
+ }
|
|
|
+
|
|
|
document.body.appendChild(root);
|
|
|
|
|
|
return {
|
|
|
instance: app.mount(root),
|
|
|
- unmount() {
|
|
|
- app.unmount();
|
|
|
- document.body.removeChild(root);
|
|
|
- },
|
|
|
+ unmount,
|
|
|
};
|
|
|
}
|