({ productId })
| 3 | import { useDispatch, useSelector } from "react-redux"; |
| 4 | |
| 5 | const Counter = ({ productId }) => { |
| 6 | |
| 7 | const { cartItems } = useSelector(state => state.cart); |
| 8 | |
| 9 | const dispatch = useDispatch(); |
| 10 | |
| 11 | const addToCartHandler = () => { |
| 12 | dispatch(addToCart({ productId })) |
| 13 | } |
| 14 | |
| 15 | const removeFromCartHandler = () => { |
| 16 | dispatch(removeFromCart({ productId })) |
| 17 | } |
| 18 | |
| 19 | return ( |
| 20 | <div className="inline-flex items-center gap-1 sm:gap-3 px-3 py-1 rounded border border-slate-200 max-sm:text-sm text-slate-600"> |
| 21 | <button onClick={removeFromCartHandler} className="p-1 select-none">-</button> |
| 22 | <p className="p-1">{cartItems[productId]}</p> |
| 23 | <button onClick={addToCartHandler} className="p-1 select-none">+</button> |
| 24 | </div> |
| 25 | ) |
| 26 | } |
| 27 | |
| 28 | export default Counter |
nothing calls this directly
no outgoing calls
no test coverage detected