Skip to content

Commit ed67f73

Browse files
committed
Add counter component
1 parent 60b4259 commit ed67f73

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/components/counter/Counter.tsx

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import React, { Fragment } from 'react'
2+
import { useSelector, useDispatch } from 'react-redux'
3+
import { actionTypes, selectors } from '../../features/counter'
4+
5+
const Counter: React.FC = () => {
6+
const count = useSelector(selectors.getCountValue)
7+
const dispatch = useDispatch()
8+
9+
return (
10+
<Fragment>
11+
<div className="row">
12+
<div className="col s12 m6">
13+
<div className="card blue-grey darken-1">
14+
<div className="card-content white-text">
15+
<span className="card-title">Counter component</span>
16+
<h4>
17+
Counter: <strong>{count}</strong>
18+
</h4>
19+
<p>
20+
Here you can increment and decrement counter value using buttons
21+
below. All the state updates are performed via redux actions.
22+
</p>
23+
</div>
24+
<div className="card-action">
25+
<div className="group">
26+
<button
27+
className="waves-effect waves-teal btn-flat blue"
28+
type="button"
29+
onClick={() =>
30+
dispatch({ type: actionTypes.DECREMENT_COUNTER })
31+
}
32+
>
33+
decrement
34+
</button>
35+
<button
36+
className="waves-effect waves-teal btn-flat red"
37+
type="button"
38+
onClick={() =>
39+
dispatch({ type: actionTypes.INCREMENT_COUNTER })
40+
}
41+
>
42+
increment
43+
</button>
44+
</div>
45+
</div>
46+
</div>
47+
</div>
48+
</div>
49+
</Fragment>
50+
)
51+
}
52+
53+
export default Counter

src/components/counter/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from './Counter'

0 commit comments

Comments
 (0)