I have a demo here
https://stackblitz.com/edit/react-ts-shopping-cart-ssofgc?file=Shop.tsx
Sorry this isn't the best question but
My demo is a simple shopping cart using React and Typescript.
Products can be added and removed from a cart.
My demo in stackblitz works but I have an error using the same code in my app.
In my app I get an error in the removeFromCart
I get the error here
const removeFromCart = (
e: React.MouseEvent<HTMLInputElement, MouseEvent>,
item: IProduct
) => {
let cartCopy = [...cart]; // Error here - Type 'IProduct' must have a '[Symbol.iterator]()' method that returns an iterator.
cartCopy = cartCopy.filter(cartItem => cartItem.id !== item.id);
setCart(cartCopy);
};
The error is
Type 'IProduct' must have a '[Symbol.iterator]()' method that returns an iterator.
Can anyone explain this error or how to fix it.