Sep 12, 2023
In ReactJS, the effects run when the component first mounts and when the dependencies change. If the effect returns a callback, that callback acts as a cleanup step which runs either when the component is unmounted or just before the next effect kicks in (when the dependencies change). Here, the dependencies array is empty, so the cleanup happens only when the component unmounts.