how can I invoke a trpc call inside a nested function?

I know it isn't directly possible. But is there a workaround?
7 Replies
Neto
Neto12mo ago
Use the vanilla client Will give you a promise to resolve
Solution
Huperniketes
Huperniketes12mo ago
Don't they normally do that? eg, api.posts.getAll.useQuery() in theo's t3 tutorial?
Neto
Neto12mo ago
that is the trpc tanstack query client with that you are able to handle the call in a more react way with vanilla client you can use as if was plain ts
const values = [1, 2, 3]
const tasks = values.map((elem) => client.something.something2.query(elem));
const result = await Promise.all(tasks)
const values = [1, 2, 3]
const tasks = values.map((elem) => client.something.something2.query(elem));
const result = await Promise.all(tasks)
Huperniketes
Huperniketes12mo ago
And react doesn't regard it as a hook?
Neto
Neto12mo ago
no
Huperniketes
Huperniketes12mo ago
Yeah, that did the trick. I just needed to do a little more data massaging of my stuff for everything to work. Thank you very much!