File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,11 @@ import { toggleCartHidden } from '../../redux/cart/cart.actions'
66import './cart-icon.styles.scss'
77import { ReactComponent as ShoppingIcon } from '../../assets/shopping-bag.svg'
88
9- function CartIcon ( { toggleCartHidden } ) {
9+ function CartIcon ( { toggleCartHidden, itemCount } ) {
1010 return (
1111 < div className = "cart-icon" onClick = { toggleCartHidden } >
1212 < ShoppingIcon className = "shopping-icon" />
13- < span className = "item-count" > 0 </ span >
13+ < span className = "item-count" > { itemCount } </ span >
1414 </ div >
1515 )
1616}
@@ -19,4 +19,9 @@ const mapDispatchToProps = dispatch => ({
1919 toggleCartHidden : ( ) => dispatch ( toggleCartHidden ( ) )
2020} )
2121
22- export default connect ( null , mapDispatchToProps ) ( CartIcon )
22+
23+ const mapStateToProps = ( { cart : { cartItems } } ) => ( {
24+ itemCount : cartItems . reduce ( ( accumulatedQuantity , cartItem ) => accumulatedQuantity + cartItem . quantity , 0 )
25+ } )
26+
27+ export default connect ( mapStateToProps , mapDispatchToProps ) ( CartIcon )
You can’t perform that action at this time.
0 commit comments