1import React from 'react';
2
3class Counter extends React.Component {
4 state = { count: 0 }
5
6 increment = () => {
7 this.setState({
8 count: this.state.count + 1
9 });
10 }
11
12 decrement = () => {
13 this.setState({
14 count: this.state.count - 1
15 });
16 }
17
18 render() {
19 return (
20 <div>
21 <h2>Counter</h2>
22 <div>
23 <button onClick={this.decrement}>-</button>
24 <span>{this.state.count}</span>
25 <button onClick={this.increment}>+</button>
26 </div>
27 </div>
28 )
29 }
30}
31
32export default Counter;
33