DEV Community

Discussion on: HTTP-API Integration with React Lifecycle-Methods and Hooks

 
kayis profile image
K • Edited

Ah, okay.

You supply a callback to the useEffect hook and this callback can return another callback.

The first callback is called on a mount event, the returned callback is the one that is called on an unmount event.

(If you supply an array as second argument to useEffect, the first callback is also executed if one of the elements intl this array changed between renders, if the array is empty, the first callback is only called in mount, like with my example)