Skip to content

Instantly share code, notes, and snippets.

@a7ul
Last active January 27, 2019 22:02
Show Gist options
  • Save a7ul/5c2bf589617fff0149268a2dfb03ef8d to your computer and use it in GitHub Desktop.
Save a7ul/5c2bf589617fff0149268a2dfb03ef8d to your computer and use it in GitHub Desktop.
react-webcomponentify-examples-my-input.js
import React from "react";
import { registerAsWebComponent } from "react-webcomponentify";
export class Input extends React.Component {
constructor(props) {
super(props);
this.state = { buttonText: "" };
this.onInputEnter = this.onInputEnter.bind(this);
}
onInputEnter(evt) {
this.setState({
buttonText: evt.target.value
});
}
render() {
return (
<div>
<input
style="width:200px;height:40px;padding:10px;font-size:14px;border:2px solid blue;"
type="text"
placeholder="enter some text here"
onChange={this.onInputEnter}
/>
<br />
<br />
<code>Value of this.state.buttonText: </code>
{this.state.buttonText}
</div>
);
}
}
registerAsWebComponent(Input, "my-input");
/*
In html:
<my-input></my-input>
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment