InfiniteQueries, refetch, and loading/fetching flags #3947
-
Hi all, I'm new to React Query, but have come upon an interesting problem. I am using an infinite query to maintain my scrollable list of items and am using the refetch method to reload my items after the user has made updates on a different screen. The issue is that I don't see a flag I can use to indicate the data is being "hard reloaded" so to speak by showing the users a loading icon. If I rely on isLoading, then it isn't set to true when "refetch()" is called. If I rely on isFetching, then it is set to true whenever the user causes the next batch of items to be loaded in as well (bad UI). I'm essentially trying to display a nice loading icon whenever the list is initially being loaded OR when I have called refetch(). What's the common solution for handling this for cases like pulling down to refresh and such? As a workaround, I created my own "loading" state that I trigger on and off whenever I call refetch(), and while that works it is not ideal. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
You can use |
Beta Was this translation helpful? Give feedback.
-
Hey @TkDodo ✋ I have a pretty similar use case, however, in my infinite scroll list, the user can manually refetch the infinite query by clicking a So, currently, I'm only using const isManuallyRefetching = "?"
const hasLoader = isFetchingNextPage || isManuallyRefetching I hope you can help me to figure this out 🙏 |
Beta Was this translation helpful? Give feedback.
You can use
isFetching && !isFetchingNextPage