re: HTTP-API Integration with React Lifecycle-Methods and Hooks VIEW POST


Nice post K! I think one thing that seems very subtle is how the abort is handled with hooks example. That seems a bit implicit, is there any way to make that operation more explicit?


You mean to give the user of the hook a way to call the abort manually?


I'm not sure if what I am asking fits into that question exactly. I guess I'm wondering if in the hooks world there is the explicit unmounting that the abort could be called in. It seems a bit odd that useEffect implicitly mimicks the unmount and would only then execute the callback function.

This is likely a knowledge gap in my React, but I was hoping you might be able to provide a clearer take on it.

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)

code of conduct - report abuse