Passing Array Dependencies
It’s interesting that the effect function is invoked every time there’s an update. That’s great, but it’s not always the desired functionality.
Using Effect for Specific Functionality
What if you want to run the effect function only when the component mounts?
That’s a common use case and
useEffect takes a second parameter, an array of dependencies to handle this.
If you pass in an empty array, the effect function is run only on the mount — subsequent re-renders don’t trigger the effect function.