In the last section we created our redux store inside the index such as file and wired up the store
to our component hierarchy.
Thanks to the provider had provided to us by the reactor redux library.
We're now going to progress on to creating all the different reducers or at least one reducer for right
now that's going to use inside of our redux store.
We'll create the reducer we'll then import it into this index file and replace this little dummy reducer
right here with the real one that we want to use inside of our application.
Now it's a reminder we're going to have two distinct reducers at least inside of our application.
The first is the author douceur that is going to be responsible for deciding whether or not the user
is currently logged in.
And the second will be a survey's reducer which is responsible for recording a list of all the different
surveys that a user has created.
Now over time we might add in a couple of other reducers if required.
But right now I feel pretty confident that this will at least get us started.
We're not going to create the survey's reducer just yet.
We'll come back to that later after we've kind of implemented surveys a little bit on the back end server.
So right now I want to create a file to Howze our reducer.
I want to pass it to our combined reducers call and then pass that off to our redux store.
So I'm going to change back over to my code Ed..
We're going to create a new folder to house all the different producers inside of our application.
So inside of the SIRC directory I'll make a new folder called reducers and do triple check your spelling
on reducers.
Very common typo.
I do is to flip the r in that e and they're really easy typo type automake inside the reducers directory.
We're going to immediately create two different files one is going to be intended to house the author
douceur.
So I'm going to make Auth. reduce Yes.
And do note that I'm using a lowercase a here to indicate that we are going to export a function from
this file as opposed to a component class or something like that.
Then the second file and going to make is going to be called an index file.
So index dot J Yes.
Now immediately Yes we do now have to index dot J.S. files inside of our project.
I know this is a pain.
I know it's something that is tough to get used to.
The purpose of calling these files indexed us is to allow us to simply import the reducers directory
which by convention with import statements will automatically give us any file inside that directory
that is called indexed on.
Yes.
So if you don't like the fact that we know how to index dodgiest files Trust me I'm with you.
I don't really care for it myself but it is definitely convention inside of react and redux projects.
So we're sticking with convention here.
Okay.
Well first start off inside the author Duzer file.
So I'm now inside of author reducer.
J.S. inside of here we're going to create a reducer and immediately export it.
Now as a reminder kind of assuming here that we're all at least passingly familiar with reducers we
kind of have a sense of what they do if you're not familiar with all this stuff.
You know if I'm moving too fast at this point remember you can always look up some of different resources
of attached to the end of the course and get a little refresher on redox and how it works.
OK.
So inside the author Duzer file and place our expert default statements are going to export a function
the function we called with two arguments the first will be our state object that is responsible for
this reducer and then the second object or a second argument I should say would be our action object
inside of the reducer.
We'll switch over the actions type.
Right now we don't have any types defined inside of our application.
So I'm going to assume that we're just going to have a single case the default case default from which
we will just return our state.
So we're going to assume hey no change to state is necessary.
Just return our state object like so.
OK so then the last thing we do inside of here.
Remember that our state object initially starts off as undefined.
So we have to provide some initial value for it.
So in this case I'm just going to assume that our initial state is going to be an empty object now incredibly
likely that we'll come back and change this at some point in the future.
But right now I think it's a good starting place.
OK.
So here's our Auth. reducer.
This is looking pretty good.
Let's take a quick break.
When we return we're going to import this into our reducers index file.
We'll then wired up with a combined reducers call and then hook that up to the redux store inside of
our route index DHHS file.
So I'll see you in just a second.