Not bad, not bad ones, we have covered how we can use you state whether I think it also makes sense
if we would take a look at how we can use with an object because there is a gotcha.
So, again, we're looking for the set of Holder, then we're looking for use state object.
And once we say we should see the use state object example, and of course, we just need to navigate
to that particular file, which is in the set up again, and then use state object ajaz.
And of course I would want to use my hook.
So let's go with the values.
I'm going to go with person and then that person and that is going to be equal to my use state and then
I'll pass in that object directly.
Again, that is something that I would want you to keep in mind where you can passing the variable like
what you just did with an array, or we can pass in directly.
So in this case, I'll pass in the object what it's going to be name.
Now, that name will be Peter than age will be twenty four.
So let's do that.
And then lastly, we'll have some kind of message message and I'll set this up as a string so beautifully.
I have my object.
So let's call this a random online message so I want to receive.
Of course, we are in good shape, and if we want to consult the person, of course, will be able to
see our object.
Not bad at all.
Now, the thing is, what happens if we change this value and what God you should be looking for?
Because with Aura, it was somewhat straightforward, where in one case we just wiped out all the data
when we set it back to an empty right.
And then the second thing we had the function that was just returning a new era.
Now, this is going to be a little bit different because we'll have some values that we would want to
preserve.
Now, let me showcase what I'm talking about.
I'll start with my return, where I'll set it back to a fragment.
And then in here, let's try a few adding 3s.
So first we'll look for person, name, person and notice, since it is an object, of course I have
my value.
I'm accessing my state value and then I'm just looking for a property.
Now I will copy and paste and I'll just change these ones around where of course we'll have age here.
We'll have also a message and let's say and there it is, Peter.
Twenty four and a random message.
And eventually I would want to have a button that changes the message again, button class nine for
the stylings of Bethanne and then on Click.
And in here, let's call the change message, change message a function that we haven't created yet.
So in button, let's write change message and let's come up with that function.
So in here, consed change message, that is my function.
I'm not looking for any arguments in this case, but I would want to invoke my set person.
Now what you'll notice though, that for example, if I want to change the message to a whole world,
the problem is going to be that when we invoke this function, essentially we wipe out all the values.
Remember I told you when we set up these values, the state where it can be anything that you don't
want.
So even though in the beginning we went with an object, if we invoke the function that changes the
state value and we pass in a string, this will be a string.
So originally we had an object and we're treating like an object or a person named person.
And then the message are here.
I just wipe out the data and then I say, you know what, it is going to be a hellhole.
Now, you could make an argument.
All right, but what if we would set this up as an object and I'll pass in the proper of message.
So in this case, our same message is equal to the world.
And technically, you are correct where now we will change only the message, but again, the rest of
the data gets wiped out.
So what is the solution?
Well, the solution is using a separate operator where if you remember which operator, we first copy
the values and then we come up with whichever value we would want to override.
So how we would fix this in this scenario?
I would go with that and that person and then comma.
And then I'm just going to say, you know what?
Leave these two values, the name and age as they are and overwrite only the message.
So this is the gotcha.
For example, if you're using the object, then you need to make sure that you always, always use the
separate operator.
Or there's also some other older setup where essentially you copy the old values from the state value
and then you just decide which one you would want to choose.
In this case, we want to change the whole world.
So, of course, once we click, notice how we also change only the message.