Hi and welcome back.
Today what I want to explain to you is how
to use the reducer actions that we have defined here.
For example, update first name in order to update the first name given here.
So we're going to be updating Nata to something else.
So for that we're going to need some kind
of event happening and because of that I'm going to import pressable.
And inside this pressable I'm going to put
a text from React Native and it's going to say press me to change first name.
Great. So in order to send a request to update
the first name, we're going to have to use something called dispatch.
So let's create it here so that we dispatch an action.
Great.
And the way we use this is on press we're going to say dispatch,
update first name and we're going to give it an object first name and we're going
to say that we're changing the first name to N.
Let's import this from our reducers. Save this.
And now let's press here and we see that my first name was updated to N.
And it wasn't only updated in response to the update, my title changed as well.
So we are able to track all of the state
changes and make the updates to our screens according to that.
So if I console log the user now
you are going to see that my first name is actually changed from Nata to N.
And if I reload this, my first name is going to be changed back to Nata.
And for us to avoid something like this
just in case user goes out of the application and does something else
and comes back or user completely quits the application and comes back in.
We don't want to reset to initial state that was defined in the reducers.
We're going to have to use something
called persistor and we're going to go to that in the next videos.
Thanks so much for watching and I'll see you in the next video.