useQueries combine - combining query results
Hi all.
Not sure if I'm missing something in the docs, so I wanted to ask here if anybody has done what I'm trying to achieve with useQueries.
I fire 2 queries in the useQueries and I would like to combine the results from the 1st one with the results with the 2nd one ( merging 2 api calls into one object ).
The thing is that I need the data from both to find the correct object from the second using an ID from the first.
Now I was expecting that the result array is both query results but I guess I'm missing something.
I guess I'm playing around with the possibilities of useQueries and combine 😄
Or should I simply fire them dependantly and merge after?
Cheers.
2 Replies
generous-apricot•7mo ago
You have two options, first one is to fire the second one with the result of the first one as key. That would be the normal way. That is if you can filter your second request directlyl from your bakend. If its purely a filter on the fe then yu can fire them simultaneously. However you dont need useQueries, you can just trigger your 2 useQuery
useQueries is generally used when you want to fire queries based on a dynamic array of keys. For example you have an array of ids you want to fetch, leading to several query of the same type.
useQueries({ query: articles.map(id => createGetArticleFromIdQuery(id)) })
it does adds a slight overhead of treatement so if you know what you will be querying beforehand it is recommended to do your queries directlymagic-amberOP•7mo ago
Then I guess I did misunderstand the combine property - it's just combine not modify and combine. 😄
I've solved the conundrum with dependant queries and works. Just wanted to swag it out with the useQueries 😄