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);
Unlike with useQuery , when you call useLazyQuery , it does not immediately execute its associated query. Instead, it returns a query function in its result tuple that you call whenever you're ready to execute the query.
We run a query within a React component by calling useQuery and passing it our GraphQL query string. This makes running queries from React components a breeze. When our component renders, useQuery returns an object from Apollo Client that contains loading , error , and data properties that we can use to render our UI.
useMutation will track the state of a mutation, just like useQuery does for queries. It'll give you loading, error and status fields to make it easy for you to display what's going on to your users. You'll also get the same nice callbacks that useQuery has: onSuccess, onError and onSettled.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With