Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
debabin committed Jul 3, 2024
2 parents 1db55be + 132ca80 commit 37dd742
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions docs/src/components/demo.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup>
import { createElement } from 'react';
import { createRoot } from 'react-dom/client';
import { ref, computed, onMounted, defineAsyncComponent } from 'vue';
import { shallowRef, computed, onMounted, onUnmounted, defineAsyncComponent } from 'vue';
const props = defineProps({
hook: {
Expand All @@ -13,12 +13,18 @@ const sourceLink = computed(() => {
return `https://github.com/siberiacancode/reactuse/blob/main/src/hooks/${props.hook}/${props.hook}.demo.tsx`;
});
const demoRef = ref();
const demoRef = shallowRef();
const demoRoot = shallowRef();
onMounted(async () => {
const demoComponent = await import(`../../../src/hooks/${props.hook}/${props.hook}.demo.tsx`);
const root = createRoot(demoRef.value);
root.render(createElement(demoComponent.default, {}, null));
demoRoot.value = createRoot(demoRef.value);
demoRoot.value.render(createElement(demoComponent.default, {}, null));
});
onUnmounted(() => {
if (!demoRoot.value) return;
demoRoot.value.unmount();
});
</script>

Expand Down

0 comments on commit 37dd742

Please sign in to comment.