Lesson 5Debugging hooks
When something doesn’t work using hooks, several things can be the cause of the problem:
- if you forgot a value in a dependency array of a
useEffect, updating a value may not trigger the effect you want; - if you trigger an effect unconditionally (without checking the value of a local state, for instance), you may cause an infinite loop in your component (see section dedicated to infinite loops);
- if you forgot to update a state or update it with the wrong value, the component might not render as you expect.
So you can find most bugs with hooks by checking two things: first, the value of the local states of your component, and then the dependencies of the effects functions.