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•15mo 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.useQuery | TanStack Query React Docs
const {
data,
xenial-black•15mo ago
React Query Data Transformations
Learn the possibilities to perform the quite common and important task of transforming your data with react-query
plain-purpleOP•15mo 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•15mo ago
If you can share a code env, I can try
plain-purpleOP•15mo ago
Great, thanks!