In this video we're going to move on to it.
Rule number three around reducers.
So this one is not the worst thing in the world with the reducer.
We must not reach out of itself.
Now that term isn't super clear also a diagram just a second but essentially reduced or must not reach
out of itself or out of its own function to decide what value to return.
And so with this rule right here the declaration or the summation of it what we usually say about reducers
are that they are supposed to be pure.
So let me tell you a little bit more about what this rule is really talking about.
All right so the idea here is that anytime that we call a producer with an action and our previous state
value we're not supposed to reach out of this function whatsoever we are not supposed to go off and
make an API request or to try to read some file off our hard drive or to solicit the user for some input
or to reach into the DOM and try to pull some value out of a div or a label or input or something like
that.
When a producer gets called it is only supposed to look at the previous state value and the action object
to decide what to return.
So inside of all reducers that we write like our posts reduce right here we are never going to write
any code.
I mean the label is as bad that says like return document dot document dot query selector of some like
input element or something like that.
We're never going to try to return the result of making some network requests like ex-CEO get my list
a post or something like that.
The only thing that we're ever going to return is going to be some computation done on the two arguments.
So like that state argument the first argument and the action that this thing gets called with so good
we would return some type of combination or variation based upon the state plus action objects.
Now this is not real code right here.
This is just to give you an idea we want to take that state argument and the action argument.
We want to do some computation on them.
You know maybe a for loop maybe filtering maybe whatever it needs to be.
And that's going to be the value that we return.
We're never going to reach out of this producer Now again this entire idea right here is what we refer
to as keeping a producer here.
So with a pure function or a pure reducer we are only ever going to return values that use there it's
input arguments.
Okay so that's it.
Let's take another quick pause.
The next rule is where things start to get really interesting.
All right.
So just hold on for a second and we'll tackle this last rule in the next video.