B1: React Query deeper adoption (P1–P3) #86
|
|
@ -13,10 +13,21 @@ import ErrorBoundary from '@/components/ErrorBoundary';
|
||||||
import PageLoader from '@/components/PageLoader';
|
import PageLoader from '@/components/PageLoader';
|
||||||
|
|
||||||
// TanStack Query
|
// TanStack Query
|
||||||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
import { QueryClient, QueryClientProvider, QueryCache } from '@tanstack/react-query';
|
||||||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
import { ReactQueryDevtools } from '@tanstack/react-query-devtools';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
|
||||||
const queryClient = new QueryClient({
|
const queryClient = new QueryClient({
|
||||||
|
// Global error handling: pages render an inline error on the *initial* load
|
||||||
|
// (no data yet), so only surface a toast when a *background refetch* fails
|
||||||
|
// while stale data is still shown — otherwise the failure would be silent.
|
||||||
|
queryCache: new QueryCache({
|
||||||
|
onError: (error, query) => {
|
||||||
|
if (query.state.data !== undefined) {
|
||||||
|
toast.error(error?.message || 'Could not refresh — showing the last data.');
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}),
|
||||||
defaultOptions: {
|
defaultOptions: {
|
||||||
queries: {
|
queries: {
|
||||||
staleTime: 1000 * 60 * 2, // 2 minutes
|
staleTime: 1000 * 60 * 2, // 2 minutes
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue