Skip to content

Instantly share code, notes, and snippets.

@TCotton
Created February 13, 2017 12:36
Show Gist options
  • Save TCotton/da30c2e938e8a1aaf6df3dfc53ba9a45 to your computer and use it in GitHub Desktop.
Save TCotton/da30c2e938e8a1aaf6df3dfc53ba9a45 to your computer and use it in GitHub Desktop.
React change state view dynamically
export default class SetValueExample extends React.Component {
constructor() {
super();
this.state = {
myName: '',
};
}
setValue(e) {
this.setState({[e.target.name]: e.target.value});
}
render(){
return(
<input value={this.state.myName} name="myName" onChange={this.setValue} />
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment