Just to recap every time we used a user juicer we needed to pass in to values reduce our function and
then initial state and then what we're getting back is the state and then the function that controls
it.
And in this case that is going to be a dispatch function and then we'll just call the dispatch function
with whatever action we would want and we set up actions as variables.
Because that way it was easier to avoid the mistakes where we just have a typo.
Now I also don't want to cover well why we didn't use everything within the same state because we technically
could have we could have had the reducer that is looking for everything that is looking for total as
well as car homes.
Then also keep in mind that your juicer is not going to be anymore.
A simple array.
It's not going to be an empty array that we're getting back from the local storage.
It's in fact going to be a giant object and then you're just adding a bit more complicated functionality
where you still need to return to host state because remember that was one of the keys when you working
with producer you must and I'm going to repeat this 70000 times.
You must must must must must you must return a new state.
You cannot just mutate the state.
And if you're making your state more complicated.
Well of course if I'm adding more values in here it's not anymore.
A simple array.
In fact it's going to be an object with the properties.
Then you also need to make sure that each and every time you're going to update something within a state
that you're returning that state.
So in that case of course you would use something like this where you're going to go with return return.
Dot dot dot state.
And like I mentioned before we're going to do this a lot when we're working.
Actually we did in the redux section.
So that's the reason why I just went with the simple array and in this case I can just return here every
time I use some kind of method that returns a new array since I can use state then filter this returns
new Array anyway and then I just look for that item.
That's the reason why I didn't add everything within my state.
And the way reducer works is we use the dispatch function then we say whatever type of action we would
want to perform and then optionally we can pass in the payload.
And as you can see the real benefits of user juicer is as your project gets bigger.
Or let's say you're getting more team members because there's more structure to it.
People kind of just come in here and start updating state willy nilly they're going to have to dispatch
their actions and then with the reducer they're going to have to make sure that they're returning new
state.
And that way they're going to have some guardrails instead of somebody comes in and then just mutates
the state and everyone else's functionality has been messed up.