Skip to content

Instantly share code, notes, and snippets.

@mingfang
Last active August 9, 2023 18:58
Show Gist options
  • Save mingfang/55faf80e773e67c36f50a795471fb190 to your computer and use it in GitHub Desktop.
Save mingfang/55faf80e773e67c36f50a795471fb190 to your computer and use it in GitHub Desktop.
Svelte component to use React components
<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