729 viewsMern Amazona
0 Comments

 <ListGroup>
                            {cartItems.map((item) => (
                                <ListGroup.Item key={item._id}>  // <= this is uniqe key isnt it?
                                    {/* Warning: Each child in a list should have a unique “key” prop. Check the render method of `CartScreen`  === error . so..  it SHOWS ONLY LAST ITEM FROM CART LIST NOT ALL OF THEM WHEN YOU BUY DIFFERENT ITEMS.  So i have no idea how to fix this. i guess code is ok, HELP NEEDED. CANT FIGURE IT OUT ON MY OWN.   screenshot from CartScreen.js */}
                                    <Row className=”align-items-center”>
                                        <Col md={4}>
                                            <img
                                                src={item.image}
                                                alt={item.name}
                                                className=”img-fluid rounded img-thumbnail”
                                            ></img>{‘ ‘}
                                            <Link to={`/product/${item.slug}`}>{item.name}</Link>
                                        </Col>
                                        <Col md={3}>
                                            <Button variant=”light” disabled={item.quantity === 1}>
                                                <i className=”fas fa-minus-circle”></i>
                                            </Button>{‘ ‘}
                                            <span>{item.quantity}</span>{‘ ‘}
                                            <Button variant=”light” disabled={item.quantity === item.countInStock}>
                                                <i className=”fas fa-plus-circle”></i>
                                            </Button>
                                        </Col>
                                        <Col md={3}>${item.price}</Col>
                                        <Col md={2}>
                                            <Button variant=”light” >
                                                <i className=”fas fa-trash”></i>
                                            </Button>
                                        </Col>
                                    </Row>
                                </ListGroup.Item>
                            ))}
                        </ListGroup>

Bassir Changed status to publish November 26, 2023

hello there,

you have 2 product with same id in the cart items. based on this condition:

https://github.com/basir/mern-amazona/blob/master/frontend/src/Store.js#L33

we don’t let having 2 products with same _id in the cart. compare you code with this to fix the issue.

Bassir Posted new comment March 10, 2023
You are viewing 1 out of 1 answers, click here to view all answers.