-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwrite-a-simple-counter.js
More file actions
43 lines (40 loc) · 988 Bytes
/
Copy pathwrite-a-simple-counter.js
File metadata and controls
43 lines (40 loc) · 988 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class Counter extends React.Component {
constructor(props) {
super(props);
this.state = {
count: 0
};
// change code below this line
this.increment = this.increment.bind(this);
this.decrement = this.decrement.bind(this);
this.reset = this.reset.bind(this);
// change code above this line
}
// change code below this line
increment() {
this.setState(state => ({
count: state.count + 1,
}))
}
decrement() {
this.setState(state => ({
count: state.count - 1,
}))
}
reset() {
this.setState(state => ({
count: 0,
}))
}
// change code above this line
render() {
return (
<div>
<button className='inc' onClick={this.increment}>Increment!</button>
<button className='dec' onClick={this.decrement}>Decrement!</button>
<button className='reset' onClick={this.reset}>Reset</button>
<h1>Current Count: {this.state.count}</h1>
</div>
);
}
};