I am using useQuery
from react-query
to fetch data that I only want the query to run in some condition. How can I use it?
following is my code to use useQuery
const query = useQuery<APIResponse, Error>(
[{query: creatGQL, variables: variables}],
async () => {
const result: APIResponse = await ucFetch(apiUrl, {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({
query: creatGQL,
variables: variables,
}),
});
return result;
} );
return query;