use-hooks/react-hooks-axios

allow call of axios when unmounting

fafo opened this issue · 2 comments

fafo commented

Hi, #16 solves the problem of not updating the state after umounting by canceling the call.
However sometimes it desiderable to run the call when the component is unmounted (ex autosave on close). It could be resolved with an option allowing axios to run after unmount, but not setting the results in the state variables. If anybody thinks this is the correct approach I could try to write a patch.

It not recommend to do things after unmounting, it may cause memory leaking, the sate of axios after unmounting is undefined

fafo commented

The state of axios shouldn't be affected by the react state, therefore I don't see problems in the network call. Instead all side effects (result data, loading state, error) do cause problems, but it should be easy to avoid them since we are no more interested. In our code (we wrote an internal hook similar to this one) we just have a flag allowing to run the network call after unmont, but skipping any state change.
Otherwise any behavior like autosave on close becames very difficult