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
Neto17mo ago
Use the vanilla client Will give you a promise to resolve
Solution
Huperniketes
Huperniketes17mo ago
Don't they normally do that? eg, api.posts.getAll.useQuery() in theo's t3 tutorial?
Neto
Neto17mo 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
Huperniketes17mo ago
And react doesn't regard it as a hook?
Neto
Neto17mo ago
no
Huperniketes
Huperniketes17mo 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!
Want results from more Discord servers?
Add your server