From the course: Next.js: Creating and Hosting a Full-Stack Site

Unlock this course with a free trial

Join today to access over 24,500 courses taught by industry experts.

Solution: Removing items from the cart

Solution: Removing items from the cart - React.js Tutorial

From the course: Next.js: Creating and Hosting a Full-Stack Site

Solution: Removing items from the cart

(upbeat music) - [Instructor] Okay, well hopefully at this point you've given the challenge a try. So let's walk through the solution. And the solution that I'm going to show you is just one way of doing things, so if you are able to figure out how to get the functionality to work in a different way, that's fine too. So let's start off here by adding the functionality to the products page. And in order to do that, we need to implement the Remove From Cart functionality, right? Right now we just print something out to the console when we click on the Remove From Cart button. So we're going to need to actually add a function here that makes a request to the route handler for removing items from the cart. Cool, so in order to do this, what I did is I just copied the addToCart function, and I used that as a template, and I changed this to removeFromCart, changed the name, anyway. And just like with the addToCart function, I used the product ID as the argument there to make things a little…

Contents