-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounter.js
More file actions
43 lines (37 loc) · 847 Bytes
/
Counter.js
File metadata and controls
43 lines (37 loc) · 847 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
import React, { Component } from "react";
class Counter extends Component {
constructor(props) {
super(props);
this.state = {
count: 0
};
}
increment() {
// this.setState({
// count: this.state.count + 1
// },
// () => {
// console.log('Callback value', this.state.count )
// })
this.setState((prevState, props) => ({
count: prevState.count + 1
}));
console.log(this.state.count);
}
incrementFive() {
this.increment();
this.increment();
this.increment();
this.increment();
this.increment();
}
render() {
return (
<div>
<div>Count - {this.state.count}</div>
<button onClick={() => this.incrementFive()}>Increment</button>
</div>
);
}
}
export default Counter;