Last active
August 9, 2023 18:58
-
-
Save mingfang/55faf80e773e67c36f50a795471fb190 to your computer and use it in GitHub Desktop.
Svelte component to use React components
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
import {onDestroy, onMount} from "svelte" | |
export let component | |
let container | |
let root | |
onMount(async ()=> { | |
const {createRoot} = await import('react-dom/client') | |
const {createElement} = await import('react') | |
root = createRoot(container) | |
root.render(createElement( | |
component, | |
$$props | |
)) | |
}) | |
onDestroy(()=>{ | |
root.unmount() | |
}) | |
</script> | |
<span bind:this={container}/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment