export function TRPCReactProvider(props: { children: React.ReactNode; headers: Headers; // <-- Important}) { const [queryClient] = useState(() => new QueryClient()); const [trpcClient] = useState(() => api.createClient({ transformer, links: [ unauthenticatedHandler, loggerLink({ enabled: (opts) => process.env.NODE_ENV === "development" || (opts.direction === "down" && opts.result instanceof Error), }), splitLink({ condition(op) { // Add logic here to return true for paths/routes that need to set cookies return op.path.startsWith("auth."); }, true: httpBatchLink({ url: getUrl(), headers() { const heads = new Map(props.headers); heads.set("x-trpc-source", "react-no-stream"); return Object.fromEntries(heads); }, }), false: unstable_httpBatchStreamLink({ url: getUrl(), headers() { const heads = new Map(props.headers); heads.set("x-trpc-source", "react-stream"); return Object.fromEntries(heads); }, }), }), ], }), );