Skip to content

Conversation

@imskyleen
Copy link

When incrementing or decrementing the targeted item went below the list.
So I removed the filter method. I cloned cartItems in newCardItems and I map this newCardItems, in the if and the else, to add the quantity to it.
Finally, I set it in setCartItems.

When incrementing or decrementing the targeted item went below the list.
So I removed the filter method. I cloned cartItems in newCardItems and I map this newCardItems, in the if and the else, to add the quantity to it.
Finally, I set it in setCartItems.
@vercel
Copy link

vercel bot commented Apr 27, 2022

Someone is attempting to deploy a commit to a Personal Account owned by @adrianhajdin on Vercel.

@adrianhajdin first needs to authorize it.

Copy link

@georgi9603 georgi9603 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job I would add check if ids are equal to return new item otherwise the old one:
image
const newCartItems = cartItems.map((item) =>
item._id === id
? { ...item, quantity: productToUpdate.quantity + 1 }
: item
);

setCartItems([...newCartItems]);

@imskyleen
Copy link
Author

You are right it's important to add verification, good job, thank you!

@ojongfalon
Copy link

This works perfectly.
Thank you :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants