-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCounter.js
More file actions
45 lines (31 loc) · 1.04 KB
/
Counter.js
File metadata and controls
45 lines (31 loc) · 1.04 KB
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
44
45
import classes from './Counter.module.css';
import {useSelector,useDispatch} from "react-redux";
const Counter = () => {
const dispatch =useDispatch()
const counter = useSelector(state => state.counter)
const show= useSelector(state=> state.showCounter)
const incrementHandler =()=>{
dispatch({type:"increment"})
}
const increaseHandler =()=>{
dispatch({type:"increase",amount:5})
}
const decrementHandler=()=>{
dispatch({type:"decrement"})
}
const toggleCounterHandler = () => {
dispatch({type:"toggle"})
};
return (
<main className={classes.counter}>
<h1>Redux Counter</h1>
{show && <div className={classes.value}>{counter}</div>}
<div>
<button onClick={incrementHandler}>Increment</button>
<button onClick={increaseHandler}>Increase by 5</button>
<button onClick={decrementHandler}>Decrement</button></div>
<button onClick={toggleCounterHandler}>Toggle Counter</button>
</main>
);
};
export default Counter;