Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useIsFetching always returns false #3437

Closed
TkDodo opened this issue Mar 24, 2022 · 8 comments · Fixed by #3438
Closed

useIsFetching always returns false #3437

TkDodo opened this issue Mar 24, 2022 · 8 comments · Fixed by #3438
Labels

Comments

@TkDodo
Copy link
Collaborator

TkDodo commented Mar 24, 2022

Describe 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.

@tannerlinsley
Copy link
Collaborator

🎉 This issue has been resolved in version 3.34.17 🎉

The release is available on:

Your semantic-release bot 📦🚀

@tannerlinsley
Copy link
Collaborator

🎉 This issue has been resolved in version 4.0.0-alpha.22 🎉

The release is available on:

Your semantic-release bot 📦🚀

@Gitarcitano
Copy link

@TkDodo the 3.34.17 have fixed for you?

I'm using the 3.38.0 and the useIsRetching always returns 0

@TkDodo
Copy link
Collaborator Author

TkDodo commented Apr 25, 2022

Yes, try out the sandbox with the latest version.

@Gitarcitano
Copy link

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

@TkDodo
Copy link
Collaborator Author

TkDodo commented Apr 25, 2022

If you want to target multiple keys, you'd need to use the predicate function argument, or call the hook twice.

@heyuuuu
Copy link

heyuuuu commented Jun 25, 2022

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?

@heyuuuu
Copy link

heyuuuu commented Jun 25, 2022

@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 up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants