feat: add ReactAdaptor.svelte

This commit is contained in:
SethBurkart123
2025-03-17 13:46:38 +11:00
parent 9f7b46d2ad
commit fe2fa87cb5
2 changed files with 29 additions and 0 deletions
@@ -0,0 +1,27 @@
<script lang="ts">
import React from "react";
import ReactDOM from "react-dom";
import { onDestroy, onMount } from "svelte";
const e = React.createElement;
let container: HTMLDivElement;
onMount(() => {
const { el, children, class: _, ...props } = $$props;
try {
ReactDOM.render(e(el, props, children), container);
} catch (err) {
console.warn(`react-adapter failed to mount.`, { err });
}
});
onDestroy(() => {
try {
ReactDOM.unmountComponentAtNode(container);
} catch (err) {
console.warn(`react-adapter failed to unmount.`, { err });
}
});
</script>
<div bind:this={container} class={$$props.class}></div>