Skip to content

Instantly share code, notes, and snippets.

@nirsky
Created December 25, 2018 12:33
Show Gist options
  • Save nirsky/1253db73812b224cf4b3944a03d58bd5 to your computer and use it in GitHub Desktop.
Save nirsky/1253db73812b224cf4b3944a03d58bd5 to your computer and use it in GitHub Desktop.
//Class
class CounterButton extends Component {
constructor() {
super();
this.state = {
count: 0
}
}
render() {
return <button onClick={() => this.setState({ count: this.state.count + 1 })}>
{ this.state.count }
</button>
}
}
//Hooks
const CounterButton = props => {
const [count, setCount] = useState(0);
return <button onClick={() => setCount(count + 1)}>
{ count }
</button>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment