Early on in the project, I showed you how we can set up a initial store by passing it as a second argument
in our create store.
In Redox, their alternative way, how we can pass in the store or initial state into our producer.
And the concept is following.
Where has your application grows bigger?
You would want to start combining your producers.
So essentially you don't want to set up all the functionality in one reducer.
So that's why you'll start setting up separate producers.
And in that case you would want to pass in the state directly in the register.
But at the moment we already know that if I remove my initial store, of course I will have an error
because my producer will get on the phone, because at the moment, notice I have my state, I'm relying
on my old state, but since initially state is undefined, then all the functionality goes bananas.
Now I can tell right away that we will not implement the whole setup for combined reducers where we
set up separate producers and then combine them together because I think our application is not big
enough.
So it doesn't really make sense.
But since I would want you would be aware of the other setup as well.
I'll show you how I can pass initial store directly in the register.
So we removed it from create store.
We got an error.
OK, we already expected that.
Now, how does it work?
Well, reducer is a function, correct in function.
We have something called default parameters that came along with ESX and the way we write default parameters
is in a following fashion where if I have my parameter and for example, if my parameter is undefined,
I'll set it to some kind of default value.
And you already saw that in the card container where I had the card prop that was coming, of course,
from my maps that props, but I also set it equal to an empty array.
So, for example, if for some reason my card is not an array, then at least I'll have the empty array
as a default value.
Because if we have the statement that is depending on that, since I'm checking for the card length,
then I'm saying if it is equal to zero, then display this and then if it's not, then display something.
At least I will have something.
So it's not going to be an error and we'll do exactly the same introducer.
So I have my state and I know that initially it will be undefined.
But of course in this case I could set it equal to whatever I have in my initial store.
Now, one thing that I would need to do is, of course, cut it out from the app.
Just let me grab it, then copy and paste in the reducer like so now I'll change these values around.
Of course, I don't need them anymore, so I will go with zero and zero and also remember that we have
the car items so we would need to import our car items.
So for the time being, let me say it, of course we'll still have an error because I haven't assigned
my state something.
But let me head back to objets and of course I can just copy and paste or cut it out.
I don't need it.
So let me cut it out and then in the reducer, I don't know, right after the actions, I guess I will
import my car items and now I'll set my store if it is undefined, which it will be undefined in the
beginning, equal to my initial store.
And now you'll see that moment.
We said everything again works and again, it comes in very handy.
Once you start combining reducers, once you start splitting up the code from one producer into multiple
juicers and you're able to pass in the actual state directly in the producer.
So, for example, you could have some kind of modal reducer where it will have only one property.
Is the model open?
And then you'll toggle that because there's really no point for you to keep on adding everything within
that one state object and then keep on setting up the functionality because eventually it will get hard
to manage again.
We will not cover this in this project.
But I wanted you to be aware of the fact that not only we can pass in our initial store when we set
up our create store, but also we can do that directly in reducer if we use S6 default parameters or
if the parameter is undefined, then I just said equal to my initial store and all my functionality
will still or.