Lesson 2. Trigger side effects with useEffect 5. What to include in the dependencies array?
The safest is to declare every variable you use inside the body of function
passed to useEffect as a dependency. These variables may be props, local
states, etc.
Some variables, such as the setters returned by useState, don’t change during
the component lifecycle, so it isn’t necessary to put them in the dependencies.
However, it won’t cause any problem if you do.
Sometimes, you may need to put a state variable you update in the useEffect as
a dependency. Be careful not to create an infinite loop in this scenario! (We’ll
see in a next lesson how to deal with potential infinite loops.)