code-share/src/app/providers.tsx

38 lines
945 B
TypeScript
Raw Normal View History

2024-02-18 21:14:41 +07:00
"use client";
import React, { useState } from "react";
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
import trpc, { getBaseUrl } from "@/lib/trpc";
import { httpBatchLink } from "@trpc/react-query";
type Props = {
children: React.ReactNode;
};
const Providers = ({ children }: Props) => {
2024-02-21 02:01:35 +07:00
const [queryClient] = useState(() => new QueryClient());
2024-02-18 21:14:41 +07:00
const [trpcClient] = useState(() =>
trpc.createClient({
links: [
httpBatchLink({
url: getBaseUrl() + "/api/trpc",
headers() {
return {};
},
2024-02-21 02:01:35 +07:00
fetch(input, init = {}) {
return fetch(input, { ...init, cache: "no-store" });
},
2024-02-18 21:14:41 +07:00
}),
],
})
);
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
};
export default Providers;