Search code examples
react-nativereact-apolloapollo-client

multiple usequeries in a single component


I am unable to get the data by using the useQuery in the below mentioned way

const { data:data1 } = useQuery(Get_Doctor);
const {  loading, error,data } = useQuery(GET_Branch);

Solution

  • Indeed you can use multiple queries

    const queryMultiple = () => {
      const res1 = useQuery(Get_Doctor);
      const res2 = useQuery(GET_Branch);
      return [res1, res2];
    }
    
    const [
        { loading: loading1, data: data1 },
        { loading: loading2, data: data2 }
    ] = queryMultiple()
    

    What you want to do is compose multiple useQuery into your own custom hook:

    Reference

    But still, its just a syntactic sugar