code-share/renderer/providers.tsx

49 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-02-18 21:14:41 +07:00
import React, { useState } from "react";
import { QueryClientProvider, QueryClient } from "@tanstack/react-query";
2024-02-22 12:14:58 +00:00
import trpc, { getBaseUrl } from "~/lib/trpc";
2024-02-24 00:27:52 +00:00
import { toast } from "~/lib/utils";
2024-02-18 21:14:41 +07:00
import { httpBatchLink } from "@trpc/react-query";
2024-02-24 00:27:52 +00:00
import { Toaster } from "~/components/ui/sonner";
2024-02-18 21:14:41 +07:00
type Props = {
children: React.ReactNode;
};
const Providers = ({ children }: Props) => {
2024-02-24 00:27:52 +00:00
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
mutations: {
onError(err) {
toast.error(err.message);
},
},
},
})
);
2024-02-18 21:14:41 +07:00
const [trpcClient] = useState(() =>
trpc.createClient({
links: [
httpBatchLink({
url: getBaseUrl() + "/api/trpc",
headers() {
return {};
},
}),
],
})
);
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
2024-02-24 00:27:52 +00:00
<QueryClientProvider client={queryClient}>
{children}
<Toaster />
</QueryClientProvider>
2024-02-18 21:14:41 +07:00
</trpc.Provider>
);
};
export default Providers;