How can I set data to only update after a successful query is complete?
I understand
data
from useQuery()
will be undefined initially, but when the query is refetching I don't want data to change until the new data has come in. Instead it briefly changes back to undefined
before updating to new data. Does useQuery()
have an option for the behaviour I want or do I have to store query results myself with useState()
and useEffect()
s?2 Replies
modern-teal•14mo ago
That sounds like how useQuery already works, stale-while-revalidate. Do you have gcTime set very low? Maybe your queryFn returns undefined?
metropolitan-bronze•14mo ago
React Query FAQs
Answering the most frequently asked React Query questions