Skip to content

Instantly share code, notes, and snippets.

@fay-jai
Created April 19, 2016 06:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fay-jai/6c3418a3211a4a0e6eacf17e35e1c038 to your computer and use it in GitHub Desktop.
Save fay-jai/6c3418a3211a4a0e6eacf17e35e1c038 to your computer and use it in GitHub Desktop.
Component Backing Instances in React
// 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);
@yangshun
Copy link

There's a typo in findDOMNode on line 38: ReactDOM.findDDOMNode(componentInstance);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment