T
TanStack4y ago
eastern-cyan

How to manually setQueryData and timestamp so not stale

I want to manually setQueryData for a new query that doesn't yet exist in the cache. I want it to be considered not stale. My useQuery does staleTime for 500ms - but this doesn't seem to be working. It seems setQueryData sets the data but the data is instantly stale. So refetchOnMount is causing it to refetch.
6 Replies
eastern-cyan
eastern-cyanOP4y ago
Im using v3
harsh-harlequin
harsh-harlequin4y ago
setQueryData will set the data to be upatedAt "now" unless you pass in the updatedAt timestamp not sure if 500ms is enough from the time when you call setQueryData until to the point where the query is mounted. it depends on your code I'd say
eastern-cyan
eastern-cyanOP4y ago
Oh thank you very much! Is there a react-query way to make it "next-fetch" should return cached?
harsh-harlequin
harsh-harlequin4y ago
No, the cache is time based
eastern-cyan
eastern-cyanOP4y ago
ah you're right i just tested it, it was taking 853ms thanks man so much for your consistent help to everyone

Did you find this page helpful?