6 Replies
flat-fuchsia•3y ago
I might be missing something but I think the
useEffect() is not required: when router.query.page or page_size changes, useQuery will automatically refetch the data since those values are in the queryKey. Was there another reason for using prefetchQuery?ratty-blushOP•3y ago
hello @julien . I followed the example from react query's website for paginated queries. On examples, this code was written by them to prefetch the next page.
vicious-gold•3y ago
If you prefetch the next page right away, you need to make sure that the staleTime is sufficient? Otherwise when the query for next page gets active, it might be already stale
flat-fuchsia•3y ago
Oh my bad, I didn't realize it was the next page that was being prefetched!
ratty-blushOP•3y ago
ok! how do i do that? I assume that if i don't include the staleTime method, it assumes it wiill always be the latest
flat-fuchsia•3y ago
Even if the data is stale when the query for the next page gets active, data will be served from the cache and refetch will happen in the background so that should be fine as far as I know. The code looks good to me overall!
