OK, and I think we will start with increased functionality, because decrease is a bit more complicated
since you would want to remove the item if the amount is less than one, but the functionality is very
similar to increase.
So I think once we're done with increase, it is going to be much more easier to work with a decrease.
Same old spiel instead of console log, we're turning a new object.
So let's go over the return and order that now we're copying, of course, our state.
And then we could technically set up all our functionality similar way how we have with remove.
So I could just say carte and then set up the functionality.
However, there's more lines of code and I think it might get confusing.
That's the reason why I'm going to set up a separate variable and just assign it to my new car.
So for the time being, I'm just going to say let.
Cart is equal to an empty array, and then I'm going to say cart is equal to tramcar.
So let me repeat, we could technically set up all the functionality that we're going to do in a second,
set it equal to time cart right away where we have the cart, and then overwrite the old cart value
in our state.
But of course, the reason why I'm setting this up as a separate variable, because there's going to
be multiple lines of code right here.
And I think it just makes it easier that we're setting up our new cart value and then we're overriding
that in our state.
Now, it's, of course, not going to be an empty array.
We will use a map method.
So the way it works, we're going to go with state.
Then the value is correct.
Then we use the method.
And that method works very similar to a filter where we have a callback function and that callback function
is called against each and every item in our returns turns.
And as a result, now with the model, we can change the values that we're returning.
So Filter was checking whether the condition matched and based on that, it was either returning or
not returning there or in this case, we will return all of them.
So all of the items will be placed in Honiara.
However, of course, we will mutated a bit where we will change the amount.
So that will be our update.
Like I said, we have our callback function and then as a parameter, we can access each and every item.
Now, what I would want to return from my cart item.
So I'm iterating over my cart items and then each and every item is represented by this card R.M. parameter.
And then I need to decide what is going to be placed in my array.
And for the time being, I'm just going to return the item the way it is.
So I'm going to go with cart item and it is a return.
So the moment as I'm clicking, nothing's happening.
I mean, I don't have any errors, but I'm also not updating my ammo.
So let's maybe start by console again just so we can see what is the Crinum.
Maybe that way you'll have a more clearer understanding of what we're accessing.
So if I can so log and then if I'm going to click on it, I notice this will give me all three items.
So I'm going to have something.
I'm going to have my pixels.
And what this represents is my array, some iterating.
All right.
That's why I can see all three items.
Now, what I would want to check, of course, I would want to check whether the ID that I'm passing
from the card item.
Remember, when we have a increase, we also pass a payload with an ID.
So if the ID matches, then what I would want to do, well, then I would want to update that amount.
I see that I have Samsung Galaxy.
Correct.
So that is the item that I just clicked on.
So I'd want to check if the ID matches and then the amount should be increased by one.
So here is going to be my setup.
If the ID matches it, then we will update amount.
If not regardless, we will still return our card item, so we will return the rest of them, the ones
that do not have a matching amount because I still want them in my card.
But the one that matches should be increased by one.
Now let me get out of the console log as always.
You can always keep it, but in my case I will get rid of it.
And now I'm going to say if Karti remedy matches to whatever I'm passing in my payload or a no action
payload ID, if that is the case, then set up a card item and set it up equal to a new value.
So now my car item will be equal to a new value.
If it doesn't match, we will return whatever we already have here.
That's it we don't really care about.
If it matches, then we will create a new one, specially updated version.
So in my case, I'm going to go with the dart.
Let me copy all the properties from the car item.
And as a side note, I just said that we will mutate.
So that was my mistake.
We will not mutate.
We'll copy everything using the spread operator and then we'll decide which property would want to change.
And of course, the one that I would want to change is the amount.
Correct, because as we increase, we would want to change this amount.
Value Summerset, copy everything that you're getting from the car item because the ID matched and this
should be the one that has the increased amount.
So instead of mutating like I have by mistake said a minute ago, we will override that, we will have
a car item.
All the values have been copied and then for the amount we'll have a new one.
So I'm going to go with cart item amount.
So whatever the amount was in the car item and add one.
So let's save that.
And now as I'm clicking on increase, check it out.
Now, the Samsung one has two items in the car and the same thing I can do for Pixel, same thing I
can do for my third one.
So.
Now, we successfully added functionality where we can increase the amount of items in our car.