Skip to content

Instantly share code, notes, and snippets.

@SherryH
Last active July 13, 2017 22:31
Show Gist options
  • Save SherryH/a54acda1dae00540e3dcc7a327203e5b to your computer and use it in GitHub Desktop.
Save SherryH/a54acda1dae00540e3dcc7a327203e5b to your computer and use it in GitHub Desktop.
import react from 'react';
class Person extends React.Component {
constructor(props) {
super(props);
this.state = {
name: ''
};
//there is no need to bind event handlers here :)
}
//notice! class methods are defined as arrow functions!
handleChange = (e) => {
this.setState({
name: e.target.value
});
}
render() {
return (
<div>
<input value={this.state.name} onChange={this.handleChange} />
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment