All files / providers react-query-provider.tsx

100% Statements 4/4
50% Branches 1/2
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 331x                 1x   1x                       1x                  
"use client";
 
import {QueryClient, QueryClientProvider} from "@tanstack/react-query";
import {ReactQueryDevtools} from "@tanstack/react-query-devtools";
import React, {useState} from "react";
 
/** Provide a browser-scoped TanStack Query client for all dashboard panels. */
export function ReactQueryProvider({children}: { children: React.ReactNode }) {
    // Keep one QueryClient instance for the lifetime of the browser session.
    const [queryClient] = useState(
        () =>
            new QueryClient({
                defaultOptions: {
                    queries: {
                        gcTime: 5 * 60 * 1000,
                        refetchOnWindowFocus: false,
                        retry: 1,
                        staleTime: 45 * 1000,
                    },
                },
            }),
    );
 
    return (
        <QueryClientProvider client={queryClient}>
            {children}
            {process.env.NODE_ENV === "development" ? (
                <ReactQueryDevtools initialIsOpen={false}/>
            ) : null}
        </QueryClientProvider>
    );
}