Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the toggleCartItemQuanitity bug #7

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Skyleen77
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]);

@Skyleen77
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.

None yet

3 participants