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

BIN
bun.lockb

Binary file not shown.

View File

@@ -18,7 +18,8 @@
"mobx": "^6.13.0", "mobx": "^6.13.0",
"mobx-react-lite": "^4.0.7", "mobx-react-lite": "^4.0.7",
"react": "^18.3.1", "react": "^18.3.1",
"react-dom": "^18.3.1" "react-dom": "^18.3.1",
"ws": "^8.18.0"
}, },
"devDependencies": { "devDependencies": {
"@todo-tests/common": "workspace:*", "@todo-tests/common": "workspace:*",

View File

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