Skip to content

Instantly share code, notes, and snippets.

@jlittlejohn
Last active May 2, 2019 02:12
Show Gist options
  • Save jlittlejohn/0532547fc46011745372e83d8b362245 to your computer and use it in GitHub Desktop.
Save jlittlejohn/0532547fc46011745372e83d8b362245 to your computer and use it in GitHub Desktop.
REACT: State Change onClick Example
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