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.

Remove cart action

Remove cart action

All right, guys. Now we want the ability to remove an item from the cart. And we're going to do the action first, so the interaction with the database and so on. And then in the video after that, we'll start to work with this button so that when we add to cart, we have the option to remove. And we also want the option to increase the quantity from here. So let's go into our cart actions. And we're going to create a new function down at the bottom. So right here, let's say, export async function. And we're going to call this remove item from cart. And this is going to remove a specific item. So let's pass in the product ID, which will be a string. And then the first thing, well, we're going to have a try catch. And let's just handle the error first, which is simple. just going to return, as we have been, a success value of false. And then for the message, we're going to use our format error function and pass in the error. So that's if something goes wrong. Now in the try, we want to…

Contents