Don't mutate state
All this is good, and now we have a fully functional reducer function that listens to actions and performs accordingly.
But wait a minute, what exactly is happening at line 16? What is this currentState variable and why do we use this all the time and not the state variable which we have defined as an argument?
Well, to keep it simply and to make a long story short, redux suggests NOT to make alterations, changes or modifications directly on change, but better to create a copy of it, make the changes there, and then return this new updated state! This technique is called not mutating the state, so not directly affect it. Redux will have unexpected results if you try to change values directly in state, and sometimes you will not get the values of the updated state but of the previous one!
Thus we use the spread operator, in order to create a fresh brand new state object, but with the same properties and values of the previous state. Then, and since the new currentState object points to a completely difference place in system's memory, we safely change anything we want there, and return this object. Once this object is returned, this is going to be the state object for the next time the reducer function will be called to it's job.
But how exactly can we call the reducer function and actually connect it with the actions functions?
Let's find out.