We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b4ff9ee commit 5f916bbCopy full SHA for 5f916bb
src/contexts/CartContext.tsx
@@ -19,8 +19,10 @@ const CartProviderComponent = ({ children }: { children: ReactNode }) => {
19
localStorage.setItem('cart-items', JSON.stringify(cart));
20
}, [cart]);
21
22
- const addToCart = (item: Omit<CartItem, 'quantity'>, quantity: number = 1) => {
23
- dispatch({ type: 'ADD', item: { ...item, quantity } });
+ // NOTE: Always adds 1-5 random units of an item to the cart
+ 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 } });
26
};
27
const decrementFromCart = (id: number) => {
28
dispatch({ type: 'DECREMENT', id });
0 commit comments