1 00:00:00,420 --> 00:00:05,220 Beautiful ones we have calculated the total as well as the card items. 2 00:00:05,220 --> 00:00:11,480 Now I can shift gears and talk about remove item increased my item all the way to a clear car. 3 00:00:11,910 --> 00:00:14,890 So one by one we're gonna solve this functionalities. 4 00:00:15,210 --> 00:00:21,240 And then I would want to collapse the use effect just so have a little bit more real estate and remove 5 00:00:21,240 --> 00:00:25,390 item is gonna be following way where we're getting back the idea. 6 00:00:25,620 --> 00:00:32,900 So of course the ideas coming from the cart item and now I'd want to use the filter method on my cart. 7 00:00:32,970 --> 00:00:40,170 So essentially cart is the array so I can use the filter method and only return the items that do not 8 00:00:40,170 --> 00:00:44,430 match the idea that I'm passing down when I click on the button. 9 00:00:44,430 --> 00:00:49,470 So each and every item has the eighty one so we're gonna click on the move button I'm gonna get that 10 00:00:49,470 --> 00:00:54,420 particular ready so that item is not going to be returned to my new car. 11 00:00:54,570 --> 00:00:59,510 And the way it's going to work is I'm a writer we're gonna call set cart. 12 00:00:59,700 --> 00:01:06,270 Then within the set cart I'm going to spurt out my cart I'm going to get whatever values I have currently 13 00:01:06,270 --> 00:01:08,820 in a cart and run filter method on them. 14 00:01:08,850 --> 00:01:14,640 Please keep in mind we could have written this in three separate lines of code or I don't know how many 15 00:01:14,670 --> 00:01:19,660 but essentially I'm just doing a one liner right now where I'm passing right away. 16 00:01:19,670 --> 00:01:23,600 The new values and I'm just gonna adding a filter to them. 17 00:01:23,730 --> 00:01:32,490 So I'm saying I would want to filter out my current cart and if the item I.D. does not match to whatever 18 00:01:32,490 --> 00:01:37,530 idea I'm getting from normal then that item is gonna be returned to our cart. 19 00:01:37,860 --> 00:01:40,730 So we're gonna say item that is of course our callback function. 20 00:01:40,890 --> 00:01:49,140 And if item I.D. does not match does not match the idea that we're passing from our Remove button then 21 00:01:49,140 --> 00:01:52,470 everything is fine and that item is gonna be returned to our car. 22 00:01:52,920 --> 00:01:56,460 So let's save it then we're gonna head over to a cart item. 23 00:01:56,520 --> 00:02:00,030 Remember we had a cart context and now would want to access. 24 00:02:00,030 --> 00:02:01,490 Of course our function. 25 00:02:01,530 --> 00:02:09,840 So let me close the suggestion then let's write that we would want to access remove item so cost remove 26 00:02:10,650 --> 00:02:18,800 item and then I'm going to say react use context use context. 27 00:02:19,040 --> 00:02:26,030 And then I'm going to use my cart context and once I have access to my cart context then when I have 28 00:02:26,120 --> 00:02:34,070 a Remove button instead of console logging we're going to run remove remove item and we're gonna pass 29 00:02:34,160 --> 00:02:39,030 in the I.D. so whatever I.D. we're getting here is a problem. 30 00:02:39,290 --> 00:02:43,150 Once we save it the moment we're going to click on let's say removing the item. 31 00:02:43,160 --> 00:02:48,110 Notice how this item is going to be removed if this is confusing to you. 32 00:02:48,170 --> 00:02:50,270 Again I'm just gonna rewrite this quickly. 33 00:02:50,270 --> 00:02:53,620 So let me come on the salt and we could have written this THIS WAY. 34 00:02:53,680 --> 00:03:00,440 WELL LET'S SAY WE'RE GONNA HAVE LET YOU cart is equal to again we're going to spread out whatever our 35 00:03:00,440 --> 00:03:06,170 current values are and we're gonna use a filter here and in this case again we're doing the same thing. 36 00:03:06,200 --> 00:03:12,090 Item and then item I.D. does not match. 37 00:03:12,130 --> 00:03:18,850 In fact the I.D. So if the item I.D. does not match the idea that we're getting from revenue item then 38 00:03:18,850 --> 00:03:21,300 that in fact item stays. 39 00:03:21,400 --> 00:03:23,330 And then again we use that card. 40 00:03:23,380 --> 00:03:26,250 So I guess it wasn't three lines of code it was two. 41 00:03:26,410 --> 00:03:33,380 And then we're just setting our new cart value equal to the new cart variable that we just calculated. 42 00:03:33,430 --> 00:03:37,930 And again in this case I just set everything in one line that would be the difference. 43 00:03:38,440 --> 00:03:44,110 And once we have our remove item functionality now we can start working on the increased amount.