Skip to content

Why do the docs recommend isPending instead of isLoading? #6297

Answered by TkDodo
eddie-dunn asked this question in General
Discussion options

You must be logged in to vote

So, why don't the docs recommend isLoading as the default way of checking loading state?

Because isPending is directly derived from the status field, while isLoading is a combined state of status and fetchStatus. Therefore, there is no guarantee that checking for isLoading and isError will result in "data is now guaranteed to be available". You'll only get that by checking isPending, and TypeScript will also only remove undefined from the union if you've checked for pending and error.

Replies: 4 comments 11 replies

Comment options

You must be logged in to vote
1 reply
@eddie-dunn
Comment options

Comment options

You must be logged in to vote
7 replies
@eddie-dunn
Comment options

@TkDodo
Comment options

@eddie-dunn
Comment options

@Donhv
Comment options

@TkDodo
Comment options

Answer selected by eddie-dunn
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
3 replies
@TkDodo
Comment options

@w90
Comment options

@chiptus
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
7 participants