Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- handleClick = (product) => {
- product['quantity'] = 1;
- let sameItem = this.state.cartItems.findIndex(item => item.id == product.id);
- console.log(sameItem);
- if(sameItem != -1){
- if(this.state.cartItems[sameItem].quantity < 10){
- this.state.cartItems[sameItem].quantity += 1;
- }
- } else {
- let cartItems = [...this.state.cartItems, product];
- this.setState({ cartItems }, () => console.log(this.state.cartItems));
- }
- console.log(this.state.cartItems);
- }
- {/* This is all im trying to display with the cart for now, but it does not increment, but even in the console it does not increment */}
- <div>
- {cartItems.map(item => (
- <p key={item.id} >{item.quantity}</p>
- ))}
- </div>
- if(this.state.cartItems[sameItem].quantity < 10){
- this.state.cartItems[sameItem].quantity += 1;
- this.setState({cartItems});
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement