Skip to content

Instantly share code, notes, and snippets.

@default-writer
Last active October 23, 2020 11:21
Show Gist options
  • Save default-writer/2c334291612c5c135402e662c46a7953 to your computer and use it in GitHub Desktop.
Save default-writer/2c334291612c5c135402e662c46a7953 to your computer and use it in GitHub Desktop.
React.Component svelte wrapper for React
<script>
import { onMount } from "svelte";
import React from "react";
import ReactDOM from "react-dom";
const e = React.createElement;
class LikeButton extends React.Component {
constructor(props) {
super(props);
this.state = { liked: false };
}
render() {
if (this.state.liked) {
return "You liked this.";
}
return e("button", { onClick: () => this.setState({ liked: true }) }, "Like");
}
}
let container;
onMount(function() {
ReactDOM.render(e(LikeButton), container);
});
</script>
<div bind:this={container}/>
@Crackiii
Copy link

Crackiii commented Sep 5, 2020

Thanks for the gist, it's helpful.

I am getting an error when I try to run it, it says:

Uncaught ReferenceError: process is not defined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment