Files
office_translator/frontend/src/providers/QueryProvider.tsx
2026-03-07 11:42:58 +01:00

39 lines
902 B
TypeScript

'use client';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { useState, type ReactNode, useCallback } from 'react';
const DEFAULT_STALE_TIME_MS = 60 * 1000;
export function QueryProvider({ children }: { children: ReactNode }) {
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
staleTime: DEFAULT_STALE_TIME_MS,
retry: 1,
refetchOnWindowFocus: false,
},
mutations: {
retry: 1,
},
},
})
);
const handleGlobalError = useCallback((error: unknown) => {
if (typeof window !== 'undefined') {
console.error('[QueryClient Error]', error);
}
}, []);
return (
<QueryClientProvider client={queryClient}>
{children}
</QueryClientProvider>
);
}
export { DEFAULT_STALE_TIME_MS };