Spectrum is now read-only. Learn more about the decision in our official announcement.


A community of developers, designers and others who love React.js. ⚛️


Anyone here that can help ? Codesandbox inside

August 15, 2021 at 6:55pm

Anyone here that can help ? Codesandbox inside

August 15, 2021 at 6:55pm (Edited 1 year ago)

August 15, 2021 at 7:20pm
with my code, I have an issue
it working not well
I have sandbox
this fucntion - removeItem
in Cart.jsx
(alexei-maslakov) will you be here ?
(working) please provide the sandbox link
are you here?
Sent you in private
That sandbox doesn't open for some reason. Did you manage to solve the problem?
here working one
No same problem
2 issue) updatedCartArr is getting changed when finalArray.splice(index,1{new object..}. the new object is getting inside updatedCartArr. It happens only if you ad 6-7 products and than play with quantity and removing items and changing the quantity again.
I don't see that in your console log. Could you provide steps to reproduce?
Your code is quite complex too. Why don't you go somewhat more conventional? ) Like having a separate component for product in cart, that could have two states - base state and deleted state. Those array operations are quite hard to track. You could have a Set of IDs of products that have been deleted. Based on those you could change the state of your product displaying components. You could undo removing a product from the cart by just deletedProductsSet.remove('<product_id>') or something similar. What you have now is not only hard to read for others, but also hard to maintain for yourself. As you can see, you yourself quite easily get confused with your own code
Having those two lists (of items in cart and items removed from cart), you could update items in cart list for example when going back to products available list. It's as easy as const updatedCartItems = currentCartItems.filter(cartItem => deletedCartItems.remove(;
I didn't understand the remove( part what is remove ?
const deletedCartItems = new Set();
That's delete, yeah )
Show more messages