T
TanStack15mo ago
plain-purple

Can I make isFetching true after 500 milliseconds ?

isFetching is useful for show/hide loading UI during fetching but sometimes API response is too quick so the loading UI is displayed and disappeared very fast. It looks like glitchy. So I wonder if I can have an option to make isFetching true after a certain milliseconds?
5 Replies
xenial-black
xenial-black15mo ago
One approach I think of is you can use dataUpdatedAt on the return value of useQuery and if the date is too quick, you can use the select option function to add a little delta time using SetTimeout for the loader to show fully.
xenial-black
xenial-black15mo ago
React Query Data Transformations
Learn the possibilities to perform the quite common and important task of transforming your data with react-query
plain-purple
plain-purpleOP15mo ago
Thanks for the response. The second article is very useful. Could you please give me some more details regarding of using dataUpdatedAt? I'm not sure how I can use it for displaying a loading UI only when isFetching is longer than 500ms
xenial-black
xenial-black15mo ago
If you can share a code env, I can try
plain-purple
plain-purpleOP15mo ago
Great, thanks!

Did you find this page helpful?