'useQueries how to get response for a certain query
Is it possible to distinguish the response, we get from useQueries. For example
const ids = ['dg1', 'pt3', 'bn5'];
const data = useQueries(
ids.map(id => (
{
queryKey: ['friends', id],
queryFn: () => get(
'/v3/friends',
{
query: {
id,
},
},
),
}
)),
);
from the response, how can I know which response is for id dg1
and so forth or is the of the responses guaranteed to be in the same order as the ids?
Solution 1:[1]
The order returned from useQueries
is the same as the input order, so in your example:
data[0]
will be forid: 'dg1'
data[1]
will be forid: 'pt3'
data[2]
will be forid: 'bn5'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | TkDodo |