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

'loading' stays true when request with 'manual' option cancels

Open dev-bjoern opened this issue 3 years ago • 5 comments

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?)

dev-bjoern avatar Dec 31 '20 15:12 dev-bjoern

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?

simoneb avatar Jan 01 '21 11:01 simoneb

Canceling the operation, at least in my use case, was the desired behavior.

dev-bjoern avatar Jan 01 '21 13:01 dev-bjoern

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.

vmlopezr avatar Feb 13 '21 18:02 vmlopezr

A PR for this is very welcome

simoneb avatar Feb 14 '21 08:02 simoneb

Reopening as the PR that closed this was reverted.

simoneb avatar Mar 30 '21 07:03 simoneb