Beautiful ones we have calculated the total as well as the card items.
Now I can shift gears and talk about remove item increased my item all the way to a clear car.
So one by one we're gonna solve this functionalities.
And then I would want to collapse the use effect just so have a little bit more real estate and remove
item is gonna be following way where we're getting back the idea.
So of course the ideas coming from the cart item and now I'd want to use the filter method on my cart.
So essentially cart is the array so I can use the filter method and only return the items that do not
match the idea that I'm passing down when I click on the button.
So each and every item has the eighty one so we're gonna click on the move button I'm gonna get that
particular ready so that item is not going to be returned to my new car.
And the way it's going to work is I'm a writer we're gonna call set cart.
Then within the set cart I'm going to spurt out my cart I'm going to get whatever values I have currently
in a cart and run filter method on them.
Please keep in mind we could have written this in three separate lines of code or I don't know how many
but essentially I'm just doing a one liner right now where I'm passing right away.
The new values and I'm just gonna adding a filter to them.
So I'm saying I would want to filter out my current cart and if the item I.D. does not match to whatever
idea I'm getting from normal then that item is gonna be returned to our cart.
So we're gonna say item that is of course our callback function.
And if item I.D. does not match does not match the idea that we're passing from our Remove button then
everything is fine and that item is gonna be returned to our car.
So let's save it then we're gonna head over to a cart item.
Remember we had a cart context and now would want to access.
Of course our function.
So let me close the suggestion then let's write that we would want to access remove item so cost remove
item and then I'm going to say react use context use context.
And then I'm going to use my cart context and once I have access to my cart context then when I have
a Remove button instead of console logging we're going to run remove remove item and we're gonna pass
in the I.D. so whatever I.D. we're getting here is a problem.
Once we save it the moment we're going to click on let's say removing the item.
Notice how this item is going to be removed if this is confusing to you.
Again I'm just gonna rewrite this quickly.
So let me come on the salt and we could have written this THIS WAY.
WELL LET'S SAY WE'RE GONNA HAVE LET YOU cart is equal to again we're going to spread out whatever our
current values are and we're gonna use a filter here and in this case again we're doing the same thing.
Item and then item I.D. does not match.
In fact the I.D. So if the item I.D. does not match the idea that we're getting from revenue item then
that in fact item stays.
And then again we use that card.
So I guess it wasn't three lines of code it was two.
And then we're just setting our new cart value equal to the new cart variable that we just calculated.
And again in this case I just set everything in one line that would be the difference.
And once we have our remove item functionality now we can start working on the increased amount.