Skip to content

How to achieve loading state between fetches when using refetchInterval #9428

Answered by TkDodo
alexchernous asked this question in Q&A
Discussion options

You must be logged in to vote

This API is not guaranteed to return anything on the first try, so I use refetchInterval to try 2 more times. During that time, the API can potentially generate and return live data which I'll display, or maybe it can't generate anything at all in which case an empty state will be shown.

I would probably make the queryFn error if the API doesn’t return anything, and then use retry to do the retries. The query will stay in pending state until all retries are done.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@alexchernous
Comment options

Answer selected by alexchernous
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants