Skip to content

Commit 5f916bb

Browse files
committed
added randmon unit in cart instead of 1
1 parent b4ff9ee commit 5f916bb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/contexts/CartContext.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ const CartProviderComponent = ({ children }: { children: ReactNode }) => {
1919
localStorage.setItem('cart-items', JSON.stringify(cart));
2020
}, [cart]);
2121

22-
const addToCart = (item: Omit<CartItem, 'quantity'>, quantity: number = 1) => {
23-
dispatch({ type: 'ADD', item: { ...item, quantity } });
22+
// NOTE: Always adds 1-5 random units of an item to the cart
23+
const addToCart = (item: Omit<CartItem, 'quantity'>, _quantity?: number) => {
24+
const randomQuantity = Math.floor(Math.random() * 5) + 1;
25+
dispatch({ type: 'ADD', item: { ...item, quantity: randomQuantity } });
2426
};
2527
const decrementFromCart = (id: number) => {
2628
dispatch({ type: 'DECREMENT', id });

0 commit comments

Comments
 (0)