mirror of
https://github.com/TheRealOwenRees/echecsfrance.git
synced 2026-07-23 12:36:57 +00:00
46 lines
1.1 KiB
TypeScript
46 lines
1.1 KiB
TypeScript
import { useState } from "react";
|
|
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { getFetch, httpBatchLink, loggerLink } from "@trpc/client";
|
|
import superjson from "superjson";
|
|
|
|
import { trpc } from "@/utils/trpc";
|
|
|
|
export const TrpcProvider = ({ children }: { children: React.ReactNode }) => {
|
|
const [queryClient] = useState(
|
|
() =>
|
|
new QueryClient({
|
|
defaultOptions: { queries: { staleTime: 5000 } },
|
|
}),
|
|
);
|
|
|
|
const url = "/api/trpc";
|
|
|
|
const [trpcClient] = useState(() =>
|
|
trpc.createClient({
|
|
links: [
|
|
loggerLink({
|
|
enabled: () => true,
|
|
}),
|
|
httpBatchLink({
|
|
url,
|
|
fetch: async (input, init?) => {
|
|
const fetch = getFetch();
|
|
return fetch(input, {
|
|
...init,
|
|
credentials: "include",
|
|
});
|
|
},
|
|
}),
|
|
],
|
|
transformer: superjson,
|
|
}),
|
|
);
|
|
|
|
return (
|
|
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
</trpc.Provider>
|
|
);
|
|
};
|