-
Notifications
You must be signed in to change notification settings - Fork 235
/
Copy pathCounter.js
39 lines (33 loc) · 974 Bytes
/
Counter.js
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
import React, { useState } from 'react';
const Counter = () => {
const [count, setCount] = useState(0);
const plus = () => {
setCount((count) => count + 1);
};
const minus = () => {
setCount((count) => count - 1);
};
const reset = () => {
setCount((count) => count - count);
};
return (
<div className="counter center">
<h1 className="counter__title">Counter App</h1>
<div className="card center">
<h2 className="card__title">Count : {count}</h2>
<div className="card__btns">
<button onClick={plus} className="btn card__btn" disabled={count === 5 ? true : false}>
+
</button>
<button onClick={minus} className="btn card__btn" disabled={count === -5 ? true : false}>
-
</button>
<button onClick={reset} className="btn card__btn">
0
</button>
</div>
</div>
</div>
);
};
export default Counter;