TRPCClientProvider refactoring

This commit is contained in:
Julien Valverdé
2024-07-18 01:51:42 +02:00
parent 5ebf7f4a6e
commit 99d192bc43
2 changed files with 9 additions and 7 deletions

View File

@@ -9,7 +9,7 @@ import { trpc } from "../trpc/trpc"
const encodeTodo = S.encodeSync(JsonifiableTodo)
export namespace VTodo {
export module VTodo {
export interface Props {
todo: Todo
}

View File

@@ -1,20 +1,22 @@
import { QueryClient, QueryClientProvider } from "@tanstack/react-query"
import { createWSClient, httpBatchLink, splitLink, wsLink } from "@trpc/client"
import { type ReactNode, useState } from "react"
import { type ReactNode, useMemo, useState } from "react"
import { trpc } from "./trpc"
export interface TRPCClientProviderProps {
children?: ReactNode
export module TRPCClientProvider {
export interface Props {
children?: ReactNode
}
}
export function TRPCClientProvider({ children }: TRPCClientProviderProps) {
export function TRPCClientProvider({ children }: TRPCClientProvider.Props) {
const [queryClient] = useState(new QueryClient())
const [wsClient] = useState(createWSClient({ url: "/rpc" }))
const [trpcClient] = useState(trpc.createClient({
const trpcClient = useMemo(() => trpc.createClient({
links: [
splitLink({
condition: op => op.type === "subscription",
@@ -27,7 +29,7 @@ export function TRPCClientProvider({ children }: TRPCClientProviderProps) {
}),
})
]
}))
}), [wsClient])
return (