August 2017
Beginner
374 pages
10h 41m
English
For Redux reducers, side effects such as logging the debug output are alright because they do not affect how the new state is computed. We just have to ensure that when we pass the same state and action, it will always return the same new state. Furthermore, we have to make sure that we never modify the current state directly.
The following reducer and side effect (highlighted) would be okay in a Redux application, as it does not affect the new state:
function counterReducer (state = 0, action) { console.log('action', action) const { type } = action switch (type) { case 'PLUS': return state + 1 case 'MINUS': return state - 1 default: return state }}
A reducer with a side effect that does affect the new state, however, ...
Read now
Unlock full access