Before we start working with single card items, I also want to show you a alternative way how we can
set up the producer.
Now, my preference is using if statements, but you can also use the switch statement.
The reason why I'm showing you these multiple options is because it is it the door and you will see
a lot in someone else's code where they use the switch statement instead.
Again, it is a preference.
I prefer using live statements, but since I would want you to be aware how you can also use a switch
statements.
That's why in this video I will comment about the code that I currently have.
Now, I'm not going to delete that because after this, really, I'll switch back to it.
But then just to showcase how we can do the same functionality using the switch statement.
All right.
The same functionality using the switch statement.
So in order to set up a switch statement, we need to go with switch keyword.
Then we we're checking for reaction type and then we replace the curly braces.
So in the curly braces, we're checking for cases.
So the same way how we're setting up their statements.
If action type is clear cut, if action type is decrease or increase and all that, we can set up cases
here.
So I go with a case and then of course I need to again use my variable.
So I'm going to go.
If the case is clear cut, what would I want to do?
So again, you would have case clear cut, case decrease and along those lines.
And then right after the call, colon, we're just going to type whatever functionality we would want.
And in our case, what is the functionality we're looking for?
Well, we would just want to again return the new object, copy the old state values, and then set
Kaat equal to an empty array.
And then as far as the switch, we also need to set up a default case.
And in a switch you just type default and then you just write what would you want to happen by default?
And in our case, what we would want by default is to return this date.
So let me write a return state, let's say it.
And in order to test it out, let's try to clear the card again.
I press and I can see that all my functionality still works.
The only difference is that I use a switch statement for my setup.
Again, I know I said this before, but it is a preference thing.
I prefer using if statements.
If you prefer using switch.
Feel free to switch.
At the end of the day, the functionality will work exactly the same.
So like I said, I'm going to uncommented whatever I had before.
And then, just so I don't want to leave it, for your reference, I'm going to comment about the switch
statement.
I'll move it somewhere down here.
And then if you'd like to access the GitHub repo and actually take a look at the switch or use it,
maybe you can always do that.
It's going to be sitting here for your reference.