useEffect
HookuseEffect
hookThe
useEffect
is a React hook that lets us specify a side effect we want to occur that is caused by rendering vs an event.
The setup function runs after a component is added or is mounted onto the page. with every re-render where the dependencies change, the effect would have to run a cleanup code and then a setup code.
The return is important for the cleanup code logic. It runs the cleanup code a final time after the component is removed.