mirror of
https://github.com/documenso/documenso.git
synced 2025-11-13 00:03:33 +10:00
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
'use client';
|
|
|
|
import { useState } from 'react';
|
|
|
|
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
|
|
import { httpBatchLink } from '@trpc/client';
|
|
import { createTRPCReact } from '@trpc/react-query';
|
|
import SuperJSON from 'superjson';
|
|
|
|
import { getBaseUrl } from '@documenso/lib/universal/get-base-url';
|
|
|
|
import { AppRouter } from '../server/router';
|
|
|
|
export const trpc = createTRPCReact<AppRouter>({
|
|
unstable_overrides: {
|
|
useMutation: {
|
|
async onSuccess(opts) {
|
|
await opts.originalFn();
|
|
await opts.queryClient.invalidateQueries();
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
export interface TrpcProviderProps {
|
|
children: React.ReactNode;
|
|
}
|
|
|
|
export function TrpcProvider({ children }: TrpcProviderProps) {
|
|
const [queryClient] = useState(() => new QueryClient());
|
|
|
|
const [trpcClient] = useState(() =>
|
|
trpc.createClient({
|
|
transformer: SuperJSON,
|
|
|
|
links: [
|
|
httpBatchLink({
|
|
url: `${getBaseUrl()}/api/trpc`,
|
|
}),
|
|
],
|
|
}),
|
|
);
|
|
|
|
return (
|
|
<trpc.Provider client={trpcClient} queryClient={queryClient}>
|
|
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
|
|
</trpc.Provider>
|
|
);
|
|
}
|