useEffect is meant to handle any sort of "side effect" (making a change in some
external system, logging to the console, making an HTTP request, etc...) that
is triggered by a change in your components data or in reaction to the
component rendering. It replaces componentDidMount, componentDidUnmount, and
componentDidReceiveProps, or some code that is run any time your state changes.
It can be challenging to grasp the nuances of its use, but by understanding
when it runs and how to control that, it can become a little bit easier to wrap
your head around.
https: