reduxjs/redux-toolkit

isFetching does not seem to act like document suggests.

grosenberry-Novetta opened this issue · 5 comments

We have a pretty normal use case where we provide a useEffect based on the loading and fetching states of our useQuery hook. When a cache is not returned the flags isLoading and isFetching work correctly however when that hook returns a cached result isFetching is always false. Documentation to me suggests that isFetching would be set to true when the hook is being fired. If this is not the intended case I'd like to understand why. I've scoured the internet for this answer and am surprised to see now results.

Current version is 1.9.5

From the docs
image

if you subscribe to something that's already in cache, you don't need to fetch anything - thus no fetching occurs

Yep, that flag indicates that an actual request is in progress. If there's a cache hit, it won't trigger a request.

I agree with your explanation but would argue you need to update your documentation. I believe there exists a use case for a flag to fire when a cache'd result is returned so that were not forced to use arrays and object definitions in our useEffect dep list.

could you give an example of what you're trying to do? generally the loading flags are tied to what you'd want to do with the UI:

  • isLoading - i have no data to display yet, so I'd want some sort of skeleton UI or perhaps a larger spinner replacing the final UI
  • isFetching - i might have data already, but I'm fetching something new, so I might want a less intrusive spinner while I keep the previous data visible

neither of these UI phases seem desirable to be displayed when you've got a cache hit, you would just want to display your normal data view.

i disagree that the docs don't accurately convey this, but am open to specific suggestions of improvements.

Seems like the fact that data exists indicates a cache hit, as does isSuccess.