export const TRPCWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const url = new URL(window.location.href);
const host = url.hostname;
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
useErrorBoundary: true,
},
mutations: {
useErrorBoundary: true,
},
},
}),
);
const [trpcClient] = useState(() =>
trpc.createClient({
transformer: superjson,
links: [
loggerLink({
enabled: (opts) => (process.env.NODE_ENV === "development" && typeof window !== undefined) || (opts.direction === "down" && opts.result instanceof Error)
}),
httpBatchLink({
url: `http://${host}:${config.webClient.port}/trpc`,
}),
],
}),
);
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
};
export const TRPCWrapper: React.FC<{ children: React.ReactNode }> = ({ children }) => {
const url = new URL(window.location.href);
const host = url.hostname;
const [queryClient] = useState(
() =>
new QueryClient({
defaultOptions: {
queries: {
useErrorBoundary: true,
},
mutations: {
useErrorBoundary: true,
},
},
}),
);
const [trpcClient] = useState(() =>
trpc.createClient({
transformer: superjson,
links: [
loggerLink({
enabled: (opts) => (process.env.NODE_ENV === "development" && typeof window !== undefined) || (opts.direction === "down" && opts.result instanceof Error)
}),
httpBatchLink({
url: `http://${host}:${config.webClient.port}/trpc`,
}),
],
}),
);
return (
<trpc.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpc.Provider>
);
};