TanStackT
TanStack2y ago
6 replies
faint-white

Query set default cacheTime

Hello, I'm trying to set the staleTime and cacheTime to infinity in the queryClient default options but the typescript is giving me a warning that I can't set the cacheTime within defualtoptions -> queries (staleTime can be set there fine). Am I missing something?

thanks!

export const queryClient = new QueryClient({
    defaultOptions: {
        queries: {
            // staleTime defines how long the data is considered fresh.
            // During this time, no background refetch will occur, and the cached data will be used.
            retry: 2,
            retryDelay: 5000,
            staleTime: Infinity, // Data will never become stale
        },
        mutations: {
            // mutation settings can also be defined here.
            // mutations generally do not have a staleTime as they are one-time operations,
            // but you can add retry or other settings if needed.
            retryDelay: 5000,
            retry: 2, // Retries failed mutations up to 3 times
        },
    },
});
Was this page helpful?