vildantursic
vildantursic
TtRPC
Created by vildantursic on 5/27/2024 in #❓-help
anyone used combine function on useQueries? I can't figure where to place it in case of tRPC
I can't figure out where to pass combine function inside tRPCs useQueries implementation
2 replies
TtRPC
Created by vildantursic on 5/11/2024 in #❓-help
Why is Uint8Array converted in object when passed as input in `.mutate({ img: u8 })` - v11
I passed Uint8Array as input for file saving but when I log it on API (trpc function) it is shown as object of same array not array itself. Why is that?
2 replies
TtRPC
Created by vildantursic on 10/6/2023 in #❓-help
Cancel useQueries with single function
is there a way to abort useQueries with function call (e.g. cancel, abort)?
5 replies
TtRPC
Created by vildantursic on 9/17/2023 in #❓-help
useQueries passing ctx data to splitLink not working
When tRPC is implemented with splitLink using useQueries does not pass cxt parameters to splitLink. Current implementation:
const trpcClient = trpc.createClient({
links: [
splitLink({
condition(opts: any) {
console.log("OPTS", opts.context.useOnline) // <= NO DATA IF useQueries used
return opts.context.useOnline
},
true: httpBatchLink({
url: "http://localhost:45835/api", // TODO: replace with online URL
headers: async () => {
const token = await getAccessTokenSilently()
return {
authorization: token,
user: JSON.stringify({
name: user?.name,
org: user?.org,
}),
application: activeApp,
}
},
}),
false: httpBatchLink({
url: "http://localhost:45835/api",
headers: async () => {
return {
authorization: "offline",
user: JSON.stringify({
name: "offline",
org: "OFFL",
}),
application: activeApp,
}
},
}),
}),
],
})
const trpcClient = trpc.createClient({
links: [
splitLink({
condition(opts: any) {
console.log("OPTS", opts.context.useOnline) // <= NO DATA IF useQueries used
return opts.context.useOnline
},
true: httpBatchLink({
url: "http://localhost:45835/api", // TODO: replace with online URL
headers: async () => {
const token = await getAccessTokenSilently()
return {
authorization: token,
user: JSON.stringify({
name: user?.name,
org: user?.org,
}),
application: activeApp,
}
},
}),
false: httpBatchLink({
url: "http://localhost:45835/api",
headers: async () => {
return {
authorization: "offline",
user: JSON.stringify({
name: "offline",
org: "OFFL",
}),
application: activeApp,
}
},
}),
}),
],
})
Implementation of useQueries usage
const data = trpc.useQueries((t) =>
machines.map((machine) =>
t.heatmap(
{
machine,
kpis: ["lossTime"],
},
{ trpc: getMachineMode(machine) } // <= This function returns { ctx: { useOnline: true/false } }
)
)
)
const data = trpc.useQueries((t) =>
machines.map((machine) =>
t.heatmap(
{
machine,
kpis: ["lossTime"],
},
{ trpc: getMachineMode(machine) } // <= This function returns { ctx: { useOnline: true/false } }
)
)
)
4 replies
TtRPC
Created by vildantursic on 9/13/2023 in #❓-help
Pass additional data from `useQuery` to context
For splitLink there is a way to pass context value through useQuery as second param { trpc: { context: { x: y } } }, but it doesn't propagate further from splitLink. Is there a similar way to pass some data to context (I want to update context data dynamicaly) after its initialization createContext? I have case where my app have route e.g. /[appName]/machine/[x] and I would like to pass appName to context so that I don't have to pass it each time with other params on useQuery. Is that possible and what would be the best way? I was trying this trpc.machine.useQuery({ id: x }, { trpc: { ctx: { app: "<appName>" } } }) and similar variations.
1 replies
TtRPC
Created by vildantursic on 9/8/2023 in #❓-help
Hybrid application with offline and online mode setup with tRPC
Hi, I was wondering if I could setup tRPC in way that one http link is using local API (for offline mode) and another uses online http link for when user logs in and connects to online service. What would be best setup, is it fine if I use splitLink in this case. Is tRPC ment for this kind of setup. Thanx
1 replies