Skip to content

Instantly share code, notes, and snippets.

@a7ul
Last active January 27, 2019 22:15
Show Gist options
  • Save a7ul/7a01ebcb68764671181077dcd0b56be9 to your computer and use it in GitHub Desktop.
Save a7ul/7a01ebcb68764671181077dcd0b56be9 to your computer and use it in GitHub Desktop.
react-webcomponentify-examples-my-button.js
import React from "react";
import { registerAsWebComponent } from "react-webcomponentify";
export const Button = props => {
return (
<button
style="height:40px;font-weight:bold;"
id={props.id}
onClick={props.onClick}
>
{props.text || "Hello"}
</button>
);
};
registerAsWebComponent(Button, "my-button");
/*
In html:
<my-button></my-button>
or
<my-button id="my-custom-btn" text="my kickass button"></my-button>
and
<script type="text/javascript">
window.onload = function() {
var myBtn = document.getElementById("my-custom-btn");
myBtn.setProps({
onClick: function() {
console.log("my-button was clicked");
}
});
};
</script>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment