MCPcopy Create free account
hub / github.com/GreatStackDev/gocart / Counter

Function Counter

components/Counter.jsx:5–26  ·  view source on GitHub ↗
({ productId })

Source from the content-addressed store, hash-verified

3import { useDispatch, useSelector } from "react-redux";
4
5const 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
28export default Counter

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected