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
Neto3y ago
Use the vanilla client Will give you a promise to resolve
Solution
Alfonso Guerra
Alfonso GuerraOP3y ago
Don't they normally do that? eg, api.posts.getAll.useQuery() in theo's t3 tutorial?
Neto
Neto3y 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)
Alfonso Guerra
Alfonso GuerraOP3y ago
And react doesn't regard it as a hook?
Neto
Neto3y ago
no
Alfonso Guerra
Alfonso GuerraOP3y 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!

Did you find this page helpful?