Skip to content

Instantly share code, notes, and snippets.

@ejangi
Last active June 19, 2021 05:08
Show Gist options
  • Save ejangi/21c16c7ff740757282dd968991eb378b to your computer and use it in GitHub Desktop.
Save ejangi/21c16c7ff740757282dd968991eb378b to your computer and use it in GitHub Desktop.
No need to work with useState() when you have a react component class.
export default class Example extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 0
};
}
render() {
return (
<div>
<p>You clicked {this.state.count} times</p>
<button onClick={() => this.setState({ count: this.state.count + 1 })}>
Click me
</button>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment