Why do the docs recommend isPending
instead of isLoading
?
#6297
-
Under https://tanstack.com/query/v5/docs/react/guides/queries#query-basics the examples given for checking for the query loading state check against
As I understand it, the I therefore think involving So, why don't the docs recommend |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 14 replies
-
I'm not sure what you mean by dependent queries. isLoading would only be true while the first fetch is in flight (in v5). I think the logic is consistent between v4 and v5. Most of the users expect to use a state that would be set to true whenever the queryFn is running and not just the first fetch. In v4 it was isLoading. In v5, its renamed to isPending. v5 isPending === v4 isLoading I'm just a fellow consumer of the library and cannot possibly know what most of the users want. All I'm saying is that the docs are consistent between v4 and v5. |
Beta Was this translation helpful? Give feedback.
-
Because |
Beta Was this translation helpful? Give feedback.
-
I am that n00b that get trapped with the |
Beta Was this translation helpful? Give feedback.
-
Renaming the most used flag in react-query = great idea for us people migrating from v4 to v5 |
Beta Was this translation helpful? Give feedback.
Because
isPending
is directly derived from thestatus
field, whileisLoading
is a combined state ofstatus
andfetchStatus
. Therefore, there is no guarantee that checking forisLoading
andisError
will result in "data is now guaranteed to be available". You'll only get that by checkingisPending
, and TypeScript will also only removeundefined
from the union if you've checked for pending and error.