I feel there are hints in the documentation about setting the default options for useQuery, but I cannot figure out exactly how. For example, the QueryClient takes a defaultOptions constructor but then it's not clear how to attach that to useQuery. Maybe it is not possible?
1 Answer
defaultOptions on the QueryClient will be applied to all queries, unless they have been specifically overwritten:
const queryClient = new QueryClient({
defaultOptions: { queries: { staleTime: 5000 } },
})
if you want to set defaults for specific queries, you can do that with:
queryClient.setQueryDefaults(['todos'], { staleTime: 3000 })
queryClient'sdefaultOptionsis the way to go. These defaults will be used by all queries using that particular query client.