Hi and welcome back.
Today I want to talk to you about redux logger
that is a middleware for redux that logs
actions and previous and next states to the console.
This is going to be helpful for you to keep state of what actions are
happening in your apps and how your state is changing according to that.
So to do that we're going to need a logger for our redux.
So let's go to the root of our project
and then let's do
npm install redux-logger
it should be very quick.
Yes, it's done.
And then we're going to import this logger from redux logger.
It doesn't need the source. Great.
And now we're going to say that we need
a new middleware that is going to get the default
middleware and is going to return the default middleware plus our logger.
So what's the issue here?
We need function here. Great.
And then what we're going to do is go back
to our app or home file and I'm going to open up our terminal.
Let's reload the application.
I'm going to press this right now
and you're going to see what's going to happen.
So we have something happening here.
Okay, so we have logged our previous state
and it tells everything to us about the store.
Okay. It says that we have a store user and its
first name was Nata and last name was Vacheishvili and user ID was one.
But then an action happened and we sent
a payload with an object of first name N which happened from here.
Exactly.
And then the type was user update first name which is right here.
And then next data generated
from the section is user and its first
name became N and last name was
Vacheishvili and user ID is one.
So this helps you keep track of any
changes happening to your store.
Whether you want to use
it is up to you or not.
I actually don't like logging so many
things so all I'm going to do is just
comment out these lines.
But if you want to use it, it's up to you.
Since you're a beginner, this will be a great help to you.
So I wanted to show you that this exists
so that you're able to track where your
errors or bugs might be coming from.
Thanks so much for listening.
In the next video we're going to talk about persisting the state when user makes
different actions such as forcing to quit your app.
See you in the next video.