Last active
May 2, 2019 02:12
-
-
Save jlittlejohn/0532547fc46011745372e83d8b362245 to your computer and use it in GitHub Desktop.
REACT: State Change onClick Example
This file contains hidden or 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
class SomeComponent extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { | |
value: 1 | |
}; | |
} | |
handleButtonChange() { | |
this.setState({ | |
value: 2 | |
}); | |
} | |
render() { | |
return ( | |
<div> | |
<h1>{this.state.value}</h1> | |
<button onClick={() => this.handleButtonChange()}>Change State</button> | |
</div> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment