useIsFetching always returns false #3437
Send to my agentDescribe the bug#
useIsFetching always shows zero when loading for the first time.
Your minimal, reproducible example#
https://codesandbox.io/s/react-query-starting-point-forked-zz56e1?file=/src/App.tsx
Steps to reproduce#
look at the sandbox isFetching should be true at some point, but it's not
note that it works if you change the order of Example and GlobalFetchingIndicator
Expected behavior#
useIsFetching should show the correct fetching count
How often does this bug happen?#
Every time
Screenshots or Videos#
No response
Platform#
all of them
react-query version#
v3 and v4
TypeScript version#
No response
Additional context#
it seems that subscription order is important. We check for isFetching when the hook mounts, and then again inside the subscription in the effect. However:
- on mount, we are not (yet) fetching
- when the effect runs and subscribes, we don't immediately receive an event, because the fetch was already triggered (useEffect execution order)
- the next even we receive is when the query has finished loading, so we are again not fetching
A potential solution could be to check for queryClient.isFetching once again if the effect runs, but outside of the subscription.
TkDodo added labelsbug
TkDodo closed this
tannerlinsley added labelsreleased
:tada: This issue has been resolved in version 4.0.0-alpha.22 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
tannerlinsley added labelsreleased on @alpha
@TkDodo the 3.34.17 have fixed for you?
I'm using the 3.38.0 and the
useIsRetchingalways returns 0Yes, try out the sandbox with the latest version.
@TkDodo
Hmm, I discovered that always returns 0 when I pass more than one key like:
queryClient.isFetching(['firstKey','secondKey'])so I think that is not supported or I'm doing something wrong
Did you know if there's some way to watch for multiples specific queries?
If you want to target multiple keys, you'd need to use the predicate function argument, or call the hook twice.
If you want to target multiple keys, you'd need to use the predicate function argument, or call the hook twice.
do you have a demo?
@TkDodo
Hmm, I discovered that always returns 0 when I pass more than one key like:
queryClient.isFetching(['firstKey','secondKey'])so I think that is not supported or I'm doing something wrong
Did you know if there's some way to watch for multiples specific queries?
i have the same question
Sign in to join this conversation.
:tada: This issue has been resolved in version 3.34.17 :tada:
The release is available on:
Your semantic-release bot :package::rocket: