We come back this way.
We left.
So in this video, let's create a button.
When we click on it, it's going to increase the counter from 0 to 1.
And that is what we call updating states.
So we have a function called set count here and we are going to use this set count to update a value
or the initial state.
So we need to create a function here.
So counts the rule is that you shouldn't call set states in the component.
If you check the rules about how we manage states or even handles, it says that you shouldn't call
such state in a component, but instead call inside a function.
So we're going to create a function here and says Increase.
Count.
And going to be my function like this.
And now here we can call said state to update my value.
So for set state sorry set count.
Where is my function to update my.
Count.
So here we pass in a callback function and here we have access to the previous state.
So previous.
States.
It.
Like this one.
And now what comes back is we can quickly console that.
Look, the previous states were going to be as the PBO states.
So when you call this function, we have access to the previous state, so let's call it a function
here.
Increase, count, quite a function and a component.
So if I call it at nine to see something, we're going to happen because we didn't call the functions
automatically like this one, like I said.
So unless you pass a function to be called remember.
So if you didn't call such state inside a component, but instead pass it to an event handler.
So here, let's create a button.
And this button here is going to say increase counts.
Let's say increase count.
Like that and now we can pass in the event on click.
When you click on you want to call the increased count and there we go.
So now let's check the console.
If I click up, sorry if I click on the increase, can see that.
First of all, the initial value was zero.
We have it here.
But the positive ones, if you click on undefined plus undefined has been replaced with a zero.
I have undefined undefined here.
So instead of this console like this one, we can take the previous one pivot state and then plus one.
And now if you click on this one, going to increase from 0 to 1.
Check it out.
Now, when I click on this, first of all, is now.
Now.
Yeah, because I didn't refresh it so that let me refresh again.
And now if I click on it, I have count from five, seven, eight, nine, ten and upwards.
That is how we make use of what the set count.
So here we can simplify making this way, plus, plus, and then remove this one, this normal JavaScript.
So let's refresh it.
And now let's click on it.
And now it's the same way.
So in the next video, we will create a button here.
When you click on it, it should decrease the state by one so we can pause this video and then try on
your own.
Otherwise, let's get continue in the next video.