File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
specialtea/src/components/UI/Buttons/CartButton Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 1
- import CartIcon from '../../../Cart/CartIcon/CartIcon ' ;
1
+ import { useContext } from 'react ' ;
2
2
3
3
import classes from './CartButton.module.css' ;
4
4
5
+ import CartIcon from '../../../Cart/CartIcon/CartIcon' ;
6
+ import CartContext from '../../../../store/CartContext/cart-context' ;
7
+
5
8
const CartButton = props => {
9
+ const context = useContext ( CartContext ) ;
10
+
11
+ const numOfCartItems = context . items . reduce ( ( current , item ) => {
12
+ return current + item . amount ;
13
+ } , 0 ) ;
14
+
6
15
return (
7
16
< button className = { classes . button } onClick = { props . onShowCart } >
8
17
< span className = { classes . icon } >
9
18
< CartIcon />
10
19
</ span >
11
20
< span > Cart</ span >
12
- < span className = { classes . badge } > 3 </ span >
21
+ < span className = { classes . badge } > { numOfCartItems } </ span >
13
22
</ button >
14
23
) ;
15
24
} ;
You can’t perform that action at this time.
0 commit comments