example of SSE streaming

This commit is contained in:
Avraham Sakal
2025-08-26 19:01:39 -04:00
parent 2d35a4683b
commit 18411402f5
2 changed files with 33 additions and 12 deletions
+16 -4
View File
@@ -32,7 +32,12 @@ import {
useMutation,
useQuery,
} from "@tanstack/react-query";
import { createTRPCClient, httpBatchLink } from "@trpc/client";
import {
createTRPCClient,
httpBatchLink,
httpSubscriptionLink,
splitLink,
} from "@trpc/client";
import type { AppRouter } from "../trpc/router.js";
function makeQueryClient() {
@@ -74,9 +79,16 @@ export default function LayoutDefault({
const [trpc] = useState(() =>
createTRPCClient<AppRouter>({
links: [
httpBatchLink({
url: "/api/trpc",
methodOverride: "POST",
splitLink({
// uses the httpSubscriptionLink for subscriptions
condition: (op) => op.type === "subscription",
true: httpSubscriptionLink({
url: "/api/trpc",
}),
false: httpBatchLink({
url: "/api/trpc",
methodOverride: "POST",
}),
}),
],
})