Working tRPC on websockets

This commit is contained in:
Julien Valverdé
2024-07-09 02:49:18 +02:00
parent e8f89db68f
commit edb46788dd
3 changed files with 10 additions and 6 deletions

View File

@@ -1,5 +1,5 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import { httpBatchLink } from "@trpc/client"
import { createWSClient, wsLink } from "@trpc/client"
import { ReactNode, useState } from "react"
import { trpc } from "./trpc"
@@ -12,13 +12,16 @@ export interface TRPCClientProviderProps {
export function TRPCClientProvider({ children }: TRPCClientProviderProps) {
const [queryClient] = useState(new QueryClient())
const [wsClient] = useState(createWSClient({ url: "ws://localhost:3001" }))
const [trpcClient] = useState(trpc.createClient({
links: [
httpBatchLink({
url: "http://localhost:8080/rpc",
headers: async () => ({}),
})
// httpBatchLink({
// url: "http://localhost:8080/rpc",
// headers: async () => ({}),
// }),
wsLink({ client: wsClient }),
]
}))