TanStackT
TanStack2y ago
2 replies
popular-magenta

Type for global error in QueryCache & MutationCache

I have a little issue. I want to define my own types for global onError callback in queryCache & mutationCache. I need error to be type of AxiosError. I can't find a working solution. I'd be glad if someone helped me. Thanks!

const [queryClient] = useState(
  () =>
    new QueryClient({
      queryCache: new QueryCache({
        onError: (error) => {
          // "error" is of type Error but I need AxiosError
        },
      }),
      mutationCache: new MutationCache({
        onError: (error) => {
          // Same here, "error" has to be type of AxiosError
        },
      }),
      defaultOptions: {
        queries: {
          staleTime: 10 * 60 * 1000,
        },
      },
    }),
);
Was this page helpful?