Skip to content

Instantly share code, notes, and snippets.

@kishanio
Created May 3, 2017 16:33
Show Gist options
  • Save kishanio/aefb6c5318d11eb3045b6b44ab0f4c9d to your computer and use it in GitHub Desktop.
Save kishanio/aefb6c5318d11eb3045b6b44ab0f4c9d to your computer and use it in GitHub Desktop.
React : Refs
// Dependecy : https://facebook.github.io/react/
const { Component } = React;
class App extends Component {
constructor() {
super();
this.state = { a: "",b : ""};
}
update(e) {
this.setState({
a : e.target.value,
b : e.target.value
});
}
updateWithRef() {
this.setState({
a : this.refs.a.value,
b : this.refs.b.value
});
}
render(){
return (
<div>
<input
type="text"
onChange={this.update.bind(this)}
/> {this.state.a}
<hr/>
<input
type="text"
onChange={this.update.bind(this)}
/> {this.state.b}
<hr/>
<input
ref="a"
type="text"
onChange={this.updateWithRef.bind(this)}
/> {this.state.a}
<hr/>
<input
ref="b"
type="text"
onChange={this.updateWithRef.bind(this)}
/> {this.state.b}
</div>
)
}
}
ReactDOM.render(
<App />,
document.getElementById("root")
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment