nurbol.dev

nurbol.dev

Parallel Queries with react-query

Function with two queries

function twoResponseFunctions() {
  return Promise.all([
    fetch('url-1').then((res) => res.json()),
    fetch('url-2').then((res) => res.json()),
  ]);
}

Use function with two queries inside useQuery

function MyComponent() {
  const twoQueries = useQuery(['myTwoQueries'], twoResponseFunctions);

  const [firstData, secondData] = twoQueries.data;
}