Complex state changes are hard to do with State Hooks
What are actions?
Actions are objects that describe a state change, for example, { type: 'CHANGE_FILTER', byAuthor: 'Daniel Bugl' }
What are reducers?
Reducers are functions that process state changes. They accept the current state and an action object and return a new state.
When should we use a Reducer Hook instead of a State Hook?
Reducer Hooks should be used when complex state changes are needed. Usually, this is the case for global state.
When setter functions of multiple State Hooks are called together, this is a good indicator for using a Reducer Hook instead.
Which steps are needed in order to turn a State Hook into a Reducer Hook?
We first need to define actions, then the reducer function, and finally a Reducer Hook
How can we create actions more easily?
We could define functions that return action objects, so called action creators
When should we merge Reducer Hooks?
When we want to avoid having two separate dispatch functions or when the same action modifies state in multiple reducers
What do we need to watch out for when merging Reducer Hooks?
We need to make sure that each reducer returns the current state for unhandled actions
What is the equivalent of an Effect Hook in class components?
In React class components we would use componentDidMount and componentDidUpdate to deal with effects
What are the advantages of using an Effect Hook versus class components?
With Effect Hooks we do not need to define both componentDidMount and componentDidUpdate. Furthermore, Effect Hooks are much easier to understand, and we do not need to know how React works internally to be able to use them.