Dynamically removing from array

  1. You should generate a unique id for each product, use something like the uuid package.

  2. Pass the id to the Removefromcart method and filter the state using the id.

  3. 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.

  4. 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).

1 Like