Skip to content

Instantly share code, notes, and snippets.

@fay-jai
Last active April 19, 2016 05:49
Show Gist options
  • Save fay-jai/d7a9d56469f8572d12c285dc4c9cbb4c to your computer and use it in GitHub Desktop.
Save fay-jai/d7a9d56469f8572d12c285dc4c9cbb4c to your computer and use it in GitHub Desktop.
React Component - CustomForm
// Here's a React Component class
class CustomForm extends React.Component {
constructor(props) {
super(props);
this.state = {
inputText: "Willson"
};
this.handleInputChange = this.handleInputChange.bind(this);
}
handleInputChange(e) {
const inputText = e.target.value;
this.setState({ inputText });
}
render() {
return (
<div className="custom-form">
<div className="custom-form-header">
<p>Hello, {this.state.inputText}</p>
</div>
<div className="custom-form-body">
<input type="text"
value={this.state.inputText}
onChange={this.handleInputChange} />
</div>
</div>
);
}
}
/*
* I'm assuming that you have React and ReactDOM available, as well as
* a HTML element with an id of "root".
* The return value of ReactDOM.render() is the component instance.
*/
var componentInstance = ReactDOM.render(<CustomForm />, document.getElementById("root"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment