Created
February 13, 2017 12:36
-
-
Save TCotton/da30c2e938e8a1aaf6df3dfc53ba9a45 to your computer and use it in GitHub Desktop.
React change state view dynamically
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
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