mirror of
https://github.com/khairul169/code-share.git
synced 2025-04-29 00:59:37 +07:00
49 lines
1.1 KiB
TypeScript
49 lines
1.1 KiB
TypeScript
import React, { useState } from "react";
|
|
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
|
|
import trpc, { getBaseUrl } from "~/lib/trpc";
|
|
import { toast } from "~/lib/utils";
|
|
import { httpBatchLink } from "@trpc/react-query";
|
|
import { Toaster } from "~/components/ui/sonner";
|
|
|
|
type Props = {
|
|
children: React.ReactNode;
|
|
};
|
|
|
|
const Providers = ({ children }: Props) => {
|
|
const [queryClient] = useState(
|
|
() =>
|
|
new QueryClient({
|
|
defaultOptions: {
|
|
mutations: {
|
|
onError(err) {
|
|
toast.error(err.message);
|
|
},
|
|
},
|
|
},
|
|
})
|
|
);
|
|
const [trpcClient] = useState(() =>
|
|
trpc.createClient({
|
|
links: [
|
|
httpBatchLink({
|
|
url: getBaseUrl() + "/api/trpc",
|
|
headers() {
|
|
return {};
|
|
},
|
|
}),
|
|
],
|
|
})
|
|
);
|
|
|
|
return (
|
|
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
<QueryClientProvider client={queryClient}>
|
|
{children}
|
|
<Toaster />
|
|
</QueryClientProvider>
|
|
</trpc.Provider>
|
|
);
|
|
};
|
|
|
|
export default Providers;
|