Hi everyone, I am trying to do something simple with a little complex twist.
I want to get the clicked item’s id. This normally works fine but now I am trying to do the same on an element that is dynamically rendered.
For instance.
Ideally I would like the “remove from cart” button to give me the id of the button that was clicked. This works fine on manually entered elements, but not the rendered ones.
Removefromcart = ( e ) => {
console.log(e.target.id)
};
As of now I am just using a very simple function, once I get the ID of the item I should be totally set to finish this myself.
Thanks in advance for your expertise.
I’m pretty sure Id is defined. It would explain a fair amount if it wasnt though.
I’ve put my full code on code sandbox so you can look at it all. The pages we have been talking about are app.js and cart.js
I finally see the issue. Thank you so much for helping me.
for the record, it wasn’t in the object because I was using the bronze ones which have an id. The problem was with the add to cart method in the button itself not having an id.
onClick={e => this.handleAddToCart(e, { title, image : imageUrl, desc, price, id //id was missing})
Thanks so much for your help. I really needed another pair of eyes.