This is part of Academy's technical curriculum for The Mark. All parts of that curriculum, including this project, are licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License.
You've been using React's useState
hook - which is by far the most common and most important out of the React hooks. Now, we'll look at useEffect
, which ranks #2 on that list.
- Predict when a
useEffect
's callback will run - Explain the role of
useEffect
dependency array
🎯 Success criterion: You can explain the
console.log
s that appear in the browser console
You'll see in the demo that useEffect
takes two arguments:
- A callback function
- An array
Here's roughly how useEffect
works:
- On every render of the component, it checks the values in its the dependency array
- If any of the values in the array have changed since the last render, then
useEffect
executes its callback