1 00:00:00,360 --> 00:00:06,660 Before we start working with single card items, I also want to show you a alternative way how we can 2 00:00:06,660 --> 00:00:07,770 set up the producer. 3 00:00:08,160 --> 00:00:13,750 Now, my preference is using if statements, but you can also use the switch statement. 4 00:00:14,100 --> 00:00:20,340 The reason why I'm showing you these multiple options is because it is it the door and you will see 5 00:00:20,340 --> 00:00:25,240 a lot in someone else's code where they use the switch statement instead. 6 00:00:25,440 --> 00:00:27,030 Again, it is a preference. 7 00:00:27,480 --> 00:00:33,150 I prefer using live statements, but since I would want you to be aware how you can also use a switch 8 00:00:33,150 --> 00:00:33,540 statements. 9 00:00:33,980 --> 00:00:38,270 That's why in this video I will comment about the code that I currently have. 10 00:00:38,280 --> 00:00:41,990 Now, I'm not going to delete that because after this, really, I'll switch back to it. 11 00:00:42,240 --> 00:00:47,070 But then just to showcase how we can do the same functionality using the switch statement. 12 00:00:47,190 --> 00:00:47,670 All right. 13 00:00:47,670 --> 00:00:50,590 The same functionality using the switch statement. 14 00:00:50,970 --> 00:00:54,660 So in order to set up a switch statement, we need to go with switch keyword. 15 00:00:54,990 --> 00:00:59,420 Then we we're checking for reaction type and then we replace the curly braces. 16 00:00:59,700 --> 00:01:02,220 So in the curly braces, we're checking for cases. 17 00:01:02,490 --> 00:01:04,710 So the same way how we're setting up their statements. 18 00:01:04,950 --> 00:01:11,400 If action type is clear cut, if action type is decrease or increase and all that, we can set up cases 19 00:01:11,400 --> 00:01:11,610 here. 20 00:01:11,850 --> 00:01:16,710 So I go with a case and then of course I need to again use my variable. 21 00:01:16,950 --> 00:01:17,640 So I'm going to go. 22 00:01:17,640 --> 00:01:21,030 If the case is clear cut, what would I want to do? 23 00:01:21,240 --> 00:01:26,100 So again, you would have case clear cut, case decrease and along those lines. 24 00:01:26,370 --> 00:01:30,900 And then right after the call, colon, we're just going to type whatever functionality we would want. 25 00:01:31,110 --> 00:01:33,600 And in our case, what is the functionality we're looking for? 26 00:01:33,900 --> 00:01:40,230 Well, we would just want to again return the new object, copy the old state values, and then set 27 00:01:40,230 --> 00:01:42,510 Kaat equal to an empty array. 28 00:01:42,750 --> 00:01:46,470 And then as far as the switch, we also need to set up a default case. 29 00:01:46,680 --> 00:01:52,590 And in a switch you just type default and then you just write what would you want to happen by default? 30 00:01:52,780 --> 00:01:57,120 And in our case, what we would want by default is to return this date. 31 00:01:57,360 --> 00:02:01,160 So let me write a return state, let's say it. 32 00:02:01,410 --> 00:02:05,220 And in order to test it out, let's try to clear the card again. 33 00:02:05,550 --> 00:02:09,420 I press and I can see that all my functionality still works. 34 00:02:09,780 --> 00:02:13,860 The only difference is that I use a switch statement for my setup. 35 00:02:14,130 --> 00:02:17,820 Again, I know I said this before, but it is a preference thing. 36 00:02:18,060 --> 00:02:19,800 I prefer using if statements. 37 00:02:20,070 --> 00:02:21,430 If you prefer using switch. 38 00:02:21,690 --> 00:02:22,770 Feel free to switch. 39 00:02:22,980 --> 00:02:26,410 At the end of the day, the functionality will work exactly the same. 40 00:02:26,640 --> 00:02:30,540 So like I said, I'm going to uncommented whatever I had before. 41 00:02:30,930 --> 00:02:36,060 And then, just so I don't want to leave it, for your reference, I'm going to comment about the switch 42 00:02:36,060 --> 00:02:36,540 statement. 43 00:02:36,730 --> 00:02:38,460 I'll move it somewhere down here. 44 00:02:38,730 --> 00:02:44,970 And then if you'd like to access the GitHub repo and actually take a look at the switch or use it, 45 00:02:44,970 --> 00:02:46,620 maybe you can always do that. 46 00:02:46,630 --> 00:02:49,350 It's going to be sitting here for your reference.