Hello everyone, this is my last issue with a 3 month long project. (I am really appreciative of FCC)
I am trying to have the item that is clicked removed from the cart array.
The issue is writing that function.
I had no problem writing the add to cart function
Thanks for your reply! I found that when googling. If it was just a simple array I would be able to remove an item from it. The issue is removing the specific part of the array that is the clicked item.
You want the item that is clicked to be removed from the cart, right?
So I click the item. The code uses indexOf() to find where that item is in the array, and then can splice() the array at that index to remove the item. Right?
You should generate a unique id for each product, use something like the uuid package.
Pass the id to the Removefromcart method and filter the state using the id.
You should really make the cart an array of objects, not an array of arrays. That way you can reference each property by name and not by index. Instead of passing the event to addCart and constructing the state from it, pass the serviceitems object and get the properties that you already have from the JSON data. Just like you are doing in the Services component.
Don’t use the DOM content to do price calculations, use the state. Do it in app.js. Using an updater function it is much easier to calculate the total then what you are doing.
I made some changes to the code and added some comments.
If you have any questions just ask, but I may not get to it today (tonight for me).