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

When we refetch a query, it doesn't set isLoading true. #2559

Closed
arslanalidev opened this issue Aug 11, 2021 · 7 comments
Closed

When we refetch a query, it doesn't set isLoading true. #2559

arslanalidev opened this issue Aug 11, 2021 · 7 comments

Comments

@arslanalidev
Copy link

Describe the bug
When we refetch a query, the isLoading property doesn't set to true. It always remains false.

To Reproduce
Steps to reproduce the behavior:

  1. Create a request using the useQuery.
  2. Extract the refetch method from the returned object.
  3. Call refetch method on any event.
  4. Now you will see that the isLoading flag is not true, if it's true then we can show the loading indication on screen.

Expected behavior
It should be set to true when we are re-fetching the data from the server.

Desktop (please complete the following information):

  • OS: Windows
  • Browser: Chrome
  • Version: 92.0.4515.131

Additional context
Nope

@TkDodo
Copy link
Collaborator

TkDodo commented Aug 11, 2021

isLoading is only true if you have a hard loading state where you have no data. When you are refetching, you most certainly have data already, which is why the query stays in success state. This is the stale-while-revalidate principle react-query is built upon.

What you are most likely looking for is the isFetching flag, which will also be true for background updates.

@ZehuaZhang
Copy link

IsFetching = isLoading + isRefetching?

@TkDodo
Copy link
Collaborator

TkDodo commented Jul 29, 2023

no, isRefetching = isFetching && !isLoading

@ZehuaZhang
Copy link

I think it's the same thing, isFetching includes isLoading and isRefetching, other words the first fetch, and refetches.

@AkshayVerma-Ipsator
Copy link

In tanStack query it is mentioned that isFetching would be of number type

@Shehryar-Naeem
Copy link

I face one issue i want to refetch the show loading show refetching loading indicator and I working correctly now I want when I like or dislike the post then refetching in background but not show refetching indicator how to do

@galletafromjell666
Copy link

I face one issue i want to refetch the show loading show refetching loading indicator and I working correctly now I want when I like or dislike the post then refetching in background but not show refetching indicator how to do

  • Create a mutation (A) for like and dislike
  • Invalidate your query key for your post on the onSuccess callback from the mutation (A)
  • Invalidating the query will cause a refetch on your useQuery. So, you only need to use value from isFetching to show the loading indicator

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants