An important concept of Redux is to guard who and what can affect your store. The who is reducers. By allowing only reducers to affect your store, we are more in control of what happens. A simple reducer is just a function that takes a state and action as parameters and is able to produce a new state based on the old state and existing state, like so:
// example reducerfunction countReducer(state = 0, action) { switch(action.type) { case "INCREMENT": return state + 1; default: return state; }}let state = countReducer(0, { type: "INCREMENT" });// 1state = countReducer(state, { type: "INCREMENT" });// 2
So, where does a reducer come into the picture in Redux? Well, the state of the store ...