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