From the course: Master Next.js by Building Scalable Apps with Routing, Databases, and Performance

Unlock this course with a free trial

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

Enabling quantity selection

Enabling quantity selection

Next, I want to implement the functionality where the quantity can be increased or decreased with size selection. So first we will implement size selection functionality. For that I will receive the set cart item from the use product context hook. Now I will add the value attribute is equal to size dot value and check item size is equal to size dot value and finally I will say on change set cart items will say previous dot map product product dot id is equal to item dot id. If it is true, then I will change the value of the size and make the quantity equal to 1. Otherwise, we will say product. Alright, let's save the code and check. And we are able to select the size options. Now we will work on increasing or decreasing the quantity of the product functionality. For that, I will navigate to the product provider component and create a function for increasing product quantity. So the logic will be to find the product by its id first and then increment the quantity by 1. So I will say…

Contents