react-hooks-axios icon indicating copy to clipboard operation
react-hooks-axios copied to clipboard

allow call of axios when unmounting

Open fafo opened this issue 6 years ago • 2 comments

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.

fafo avatar Nov 14 '19 10:11 fafo

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

int64ago avatar Nov 14 '19 12:11 int64ago

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

fafo avatar Nov 15 '19 15:11 fafo