axios-hooks
axios-hooks copied to clipboard
'loading' stays true when request with 'manual' option cancels
In the below code example, if I call 'refetch' manually and it cancels (without a new 'refetch' happening) - then the loading state variable will stay true.
const [{ data, loading }, refetch] = useAxios(
{
url: `/someUrl?param=${iCanChange}`
},
{
manual: true
}
)
I think what causes the bug: The refetch cancels because the 'iCanChange' param changes (correct behavior). No new 'refetch' is initiated because of the 'manual' option (correct behavior). But now the 'loading' state stays true (false behavior?)
Interesting edge case, I think your analysis is right.
Do you think it is correct that since this is a manual operation, if iCanChange
changes the operation is canceled?
Canceling the operation, at least in my use case, was the desired behavior.
With the addition of the manual cancel return, this can be seen as well. When clicking the cancel request
button the loading
option stays true.
https://codesandbox.io/s/axios-hooks-manual-cancellation-forked-ry6xn?file=/src/index.js
Granted, the example is a different use case from the original post #376 where it was requested for cancelling a manual request on unmount.
A PR for this is very welcome
Reopening as the PR that closed this was reverted.