Json 👺
Json 👺
TtRPC
Created by Arxk on 3/27/2025 in #❓-help
Sending FormData does not work at all
Hey, would you mind posting your specific solution using splitLink? I am having a hard time implementing this. I wish the docs explained some of this now that this feature is released.
23 replies
TtRPC
Created by Json 👺 on 10/14/2024 in #❓-help
Dynamically generate url for httpBatchLink
Currently, this seems to work, however if it's likely that the fallback value would ever be used here as opposed to the return of getUrl()
const getUrl = () => {
if (typeof window !== "undefined") {
const { hostname, protocol, port } = window.location;
const url = `${protocol}//${hostname}:${port}/api/trpc`;
return url;
}
return undefined;
};

const [queryClient] = useState(() => new QueryClient());
const [trpcClient] = useState(() =>
trpc.createClient({
links: [
httpBatchLink({
url: getUrl() ?? "http://localhost:3000/api/trpc",
// url: "http://192.168.0.16:3000/api/trpc", // For mobile device testing
// You can pass any HTTP headers you wish here
// async headers() {
// return {};
// },
transformer: SuperJSON,
}),
],
}),
);
const getUrl = () => {
if (typeof window !== "undefined") {
const { hostname, protocol, port } = window.location;
const url = `${protocol}//${hostname}:${port}/api/trpc`;
return url;
}
return undefined;
};

const [queryClient] = useState(() => new QueryClient());
const [trpcClient] = useState(() =>
trpc.createClient({
links: [
httpBatchLink({
url: getUrl() ?? "http://localhost:3000/api/trpc",
// url: "http://192.168.0.16:3000/api/trpc", // For mobile device testing
// You can pass any HTTP headers you wish here
// async headers() {
// return {};
// },
transformer: SuperJSON,
}),
],
}),
);
3 replies