Last active
April 19, 2016 05:49
-
-
Save fay-jai/d7a9d56469f8572d12c285dc4c9cbb4c to your computer and use it in GitHub Desktop.
React Component - CustomForm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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