interface IProps_Square {
message: string;
onClick: (event: React.MouseEvent<HTMLButtonElement>) => void;
}
onClick={(event: React.MouseEvent<HTMLElement>) => {
makeMove(ownMark, (event.target as any).index)
}}
interface IProps_Square {
message: string;
onClick: React.MouseEventHandler<HTMLButtonElement>;
}
const handleAddToCart = (clickedItem: CartItemType) => {
setCartItems(prev => {
// 1. Is the item already added in the cart?
const isItemInCart = prev.find(item => item.id === clickedItem.id);
if (isItemInCart) {
return prev.map(item =>
item.id === clickedItem.id
? { ...item, amount: item.amount + 1 }
: item
);
}
// First time the item is added
return [...prev, { ...clickedItem, amount: 1 }];
});
};