3

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?

1
  • someCoolResponse.queryKey[1]? Commented Apr 28, 2022 at 14:19

1 Answer 1

3

The order returned from useQueries is the same as the input order, so in your example:

  • data[0] will be for id: 'dg1'
  • data[1] will be for id: 'pt3'
  • data[2] will be for id: 'bn5'
Sign up to request clarification or add additional context in comments.

3 Comments

Is there no way to uniquely map the results to the array passed into useQueries other than the matching index? There isn't a unique id that could be associated with the results?
data will contain whatever you return from the queryFn. If you add the queryKey passed there, or any other unique id, it will be part of data
Is this included in the current docs of react query? I couldn't find that on the official docs of useQueries

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.