mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-10-02 06:13:13 +00:00
34 lines
970 B
TypeScript
34 lines
970 B
TypeScript
|
|
import { MutationCache, QueryCache, QueryClient } from "@tanstack/react-query";
|
||
|
|
import { toast } from "react-toastify";
|
||
|
|
|
||
|
|
export const queryClient = new QueryClient({
|
||
|
|
queryCache: new QueryCache({
|
||
|
|
onError: (error) => {
|
||
|
|
console.error("Query error:", error);
|
||
|
|
const message =
|
||
|
|
error instanceof Error ? error.message : "An error occurred while fetching data";
|
||
|
|
toast.error(message);
|
||
|
|
},
|
||
|
|
}),
|
||
|
|
mutationCache: new MutationCache({
|
||
|
|
onError: (error, _variables, _context, mutation) => {
|
||
|
|
if (mutation.options.meta?.suppressErrorToast) return;
|
||
|
|
|
||
|
|
console.error("Mutation error:", error);
|
||
|
|
const message =
|
||
|
|
error instanceof Error ? error.message : "An error occurred while updating data";
|
||
|
|
toast.error(message);
|
||
|
|
},
|
||
|
|
}),
|
||
|
|
defaultOptions: {
|
||
|
|
queries: {
|
||
|
|
staleTime: 5 * 60 * 1000,
|
||
|
|
gcTime: 10 * 60 * 1000,
|
||
|
|
retry: 1,
|
||
|
|
refetchOnWindowFocus: false,
|
||
|
|
},
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
export default queryClient;
|