Created
April 19, 2016 06:15
-
-
Save fay-jai/6c3418a3211a4a0e6eacf17e35e1c038 to your computer and use it in GitHub Desktop.
Component Backing Instances in React
This file contains 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> | |
); | |
} | |
} | |
// Here's a component instance | |
var componentInstance = ReactDOM.render(<CustomForm />, document.getElementById("root")); | |
// Here's a dom instance | |
var domInstance = ReactDOM.findDDOMNode(componentInstance); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There's a typo in
findDOMNode
on line 38:ReactDOM.findDDOMNode(componentInstance);