Chapter 4: Using the Reducer and Effect Hooks

  1. What are common problems with State Hooks?
    • Complex state changes are hard to do with State Hooks
  2. What are actions?
    • Actions are objects that describe a state change, for example, { type: 'CHANGE_FILTER', byAuthor: 'Daniel Bugl' }
  3. What are reducers?
    • Reducers are functions that process state changes. They accept the current state and an action object and return a new state.
  4. 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.
  5. 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
  6. How can we create actions more easily?
    • We could define functions that return action objects, so called action creators
  7. 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
  8. 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
  1. 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
  2. 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.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.15.135.63