Skip to content

Instantly share code, notes, and snippets.

@gaearon
Last active March 19, 2018 05:10
Show Gist options
  • Save gaearon/a9bbb73d57b6e4cc17d7b50807b62f9a to your computer and use it in GitHub Desktop.
Save gaearon/a9bbb73d57b6e4cc17d7b50807b62f9a to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
class Counter extends Component {
state = { value: 0 };
increment = () => {
this.setState(prevState => ({
value: prevState.value + 1
}));
};
decrement = () => {
this.setState(prevState => ({
value: prevState.value - 1
}));
};
render() {
return (
<div>
{this.state.value}
<button onClick={this.increment}>+</button>
<button onClick={this.decrement}>-</button>
</div>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment