T
TanStack3y ago
genetic-orange

when queryClient.setQueryDefaults is called, the options passed are not saved

My intention is to call setQueryData and then set the cacheTime and staleTime to Infinity :
queryClient.setQueryData(['myQueryKey'], {
myData: "someData",
});
queryClient.setQueryDefaults(['myQueryKey'], { cacheTime: Infinity, staleTime: Infinity });
queryClient.setQueryData(['myQueryKey'], {
myData: "someData",
});
queryClient.setQueryDefaults(['myQueryKey'], { cacheTime: Infinity, staleTime: Infinity });
but when i look at the DevTools, it says cacheTime: 300000. The query is in the invalid state which is what i expect.
1 Reply
fair-rose
fair-rose3y ago
defaults need to be set before a query is created. They only affect future queries

Did you find this page helpful?