From the course: Next.js Ecommerce: Build a Shopping Platform from Scratch

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Dynamic cart button

Dynamic cart button

OK, so we have the remove item from cart action, but we have no way to call it. So now we want to basically have the remove option in the Add to Cart component. Now, the first thing we need to do is pass the cart into the Add to Cart component. So we're going to go into the page where the Add to Cart component is embedded, which is app, root, product, slug, and then page TSX. And this is where we're going to use the Get My Cart. Remember, when we created this, we used it in the add action. But I said we were going to need it in other places. And this is one of those places. So we bring that in. And then we want to get the cart from that. So let's say cons cart and set that to await get my cart. And then we just want to pass that in to the add to cart component as a prop. So make sure you don't add it in here, because that's the item prop. So I'm going to add right above it, cart, and set that equal to cart. OK, now it's going to give us an error here because this Add to Cart component…

Contents