Working tRPC on websockets
This commit is contained in:
@@ -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:*",
|
||||||
|
|||||||
@@ -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 }),
|
||||||
]
|
]
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user