Differentiate refetching from actual loading #1574
-
Hey, So the use case is pretty much simple: const { data, isFetching, isFetchingNextPage } = useInfiniteQuery(["posts", { filters }], fetcher) Currently it is impossible to detect completely new refetch, when Real life use case: rendering spinner WITHOUT displaying posts when filters change, as existing posts become immediately obsolete for updated filters. Current workaround: setting staleTime to Infinity, so that background updates are completely disabled to avoid empty UI rendering so that isFetching can be simply used to detect query key change only altogether with isFetchingNextPage / isFetchingPreviousPage. EDIT: staleTime seems to be breaking query key changes, but still should give some picture of the problem What do you think? I'd say react-query could benefit from some extra option / prop where we could detect if current query is completely new. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
I don't think that's true. when the query key changes:
Usually, it's enough to show a loading spinner if the query is in This is also well documented in the api docs:
|
Beta Was this translation helpful? Give feedback.
I don't think that's true. when the query key changes:
keepPreviousData
set totrue
or populated it withinitialData
.isLoading
will betrue
, which is not the case for background refetches.Usually, it's enough to show a loading spinner if the query is in
loading
state. For background refetches, the query will stay in it's state (usuallysuccess
) and the separateisFetching
flag will be t…