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: 6 comments 16 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.
-
|
hey @TkDodo why some times isPending doesn't work, because in some use case it works Perfectly and in some not is there some property we should enable ort disable ? currently im using like this: this the above is not reliable sometimes. Plz help I'm new to TanStack Query |
Beta Was this translation helpful? Give feedback.
-
|
Cant't we just add another method to useQuery, something like refetchManually and add some state isFetchingManually? |
Beta Was this translation helpful? Give feedback.
Because
isPendingis directly derived from thestatusfield, whileisLoadingis a combined state ofstatusandfetchStatus. Therefore, there is no guarantee that checking forisLoadingandisErrorwill result in "data is now guaranteed to be available". You'll only get that by checkingisPending, and TypeScript will also only removeundefinedfrom the union if you've checked for pending and error.