-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Why function for applying query returns void instead of a promise? #7714
Labels
Comments
just to remember it's an old question asked already here: apollographql/react-apollo#3499 |
In the meantime something like the following could be used: export const useAsyncQuery = <TData, TVariables = OperationVariables>(
query: DocumentNode | TypedDocumentNode
): [
(variables: TVariables) => Promise<ApolloQueryResult<TData>>,
{ loading: boolean }
] => {
const [loading, setLoading] = useState(false);
const client = useApolloClient();
const runQuery = async (variables: TVariables) => {
setLoading(true);
const res = await client.query<TData, TVariables>({ query, variables });
setLoading(false);
return res;
};
return [runQuery, { loading }];
}; |
brainkim
added a commit
that referenced
this issue
Sep 30, 2021
brainkim
added a commit
that referenced
this issue
Oct 1, 2021
This was addressed in #8875 - thanks |
1 task
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
When I'm using
useLazyQuery
, the function for applying query returns void instead of a promise.Why can't it return a promise, like for mutations?
The text was updated successfully, but these errors were encountered: