'use client';
import { QueryClientProvider, QueryErrorResetBoundary } from '@tanstack/react-query';
import { useTranslations } from 'next-intl';
import { Component, type ErrorInfo, type ReactNode } from 'react';
import { getQueryClient } from '@/lib/query-client';
interface FallbackProps {
error: Error;
reset: () => void;
}
function QueryErrorFallback({ error, reset }: FallbackProps) {
const t = useTranslations();
return (
{t('error.description')}
{error.message && (
{error.message}
)}
);
}
interface ErrorBoundaryState {
error: Error | null;
}
class QueryErrorBoundaryInner extends Component<
{ children: ReactNode; onReset: () => void },
ErrorBoundaryState
> {
override state: ErrorBoundaryState = { error: null };
static getDerivedStateFromError(error: Error) {
return { error };
}
override componentDidCatch(error: Error, info: ErrorInfo) {
if (process.env.NODE_ENV !== 'production') {
console.error('Query error boundary caught:', error, info);
}
}
reset = () => {
this.props.onReset();
this.setState({ error: null });
};
override render() {
if (this.state.error) {
return ;
}
return this.props.children;
}
}
export function QueryProvider({ children }: { children: React.ReactNode }) {
const queryClient = getQueryClient();
return (
{({ reset }) => (
{children}
)}
);
}