Is there a way to call a trpc useQuery() multiple times?

I have a list of objects, and i would like to call the useQuery 1 time for every object in order to get some deta. Is there a good way to do this?
27 Replies
Pod
Pod2y ago
The best method would probably be for you to refactor your query to take in multiple objects
Christian Lind
this seems like such an oversight imo, might be wrong though
Pod
Pod2y ago
Can you give a bit more detail on what you're trying to do? If you don't want to get all the data in one query the next best way is probably making a component that has the query attached
Christian Lind
thats a smart workaround!
Pod
Pod2y ago
👍
Christian Lind
thanks Pod!
Pod
Pod2y ago
np, gl!
Pod
Pod2y ago
@Christian Lind There is also this if it makes more sense for your use case https://trpc.io/docs/reactjs/usequeries
useQueries() | tRPC
The useQueries hook can be used to fetch a variable number of queries at the same time using only one hook call.
Pod
Pod2y ago
Which does have some nice benefits 👌
Christian Lind
oo sweet @Pod Could i ask you one more question? Its regarding prisma and joins?
Pod
Pod2y ago
For sure
Christian Lind
Thanks mate! I have 2 tables, and would like to do a classic inner join between them, How could i achieve this using prisma?
Pod
Pod2y ago
You can do something along the lines of
prisma.tableA.findMany({
include: {
tableB: true
}
})
prisma.tableA.findMany({
include: {
tableB: true
}
})
Christian Lind
I have implemented it by using a query raw select * from SeenQuestions JOIN Xyz on SeenQuestions.questionId = Xyz.id where Xyz.subcategory=${input.subCategory} In that case - don't i have to add the relation in the prisma schema?
Pod
Pod2y ago
Yes
Want results from more Discord servers?
Add your server