forked from syhner/next-kickstart
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtrpc-provider.tsx
28 lines (25 loc) · 857 Bytes
/
trpc-provider.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
'use client';
import React, { useState } from 'react';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { httpBatchLink } from '@trpc/client';
import { transformer } from '~/trpc/transformer';
import { trpcReact } from '~/trpc/trpc-react';
import { getBaseUrl } from '~/util/getBaseUrl';
export function TrpcProvider({ children }: { children: React.ReactNode }) {
const [queryClient] = useState(() => new QueryClient({}));
const [trpcClient] = useState(() =>
trpcReact.createClient({
links: [
httpBatchLink({
url: `${getBaseUrl()}/api/trpc`,
}),
],
transformer,
})
);
return (
<trpcReact.Provider client={trpcClient} queryClient={queryClient}>
<QueryClientProvider client={queryClient}>{children}</QueryClientProvider>
</trpcReact.Provider>
);
}