Skip to content

Commit

Permalink
fix: prevent running the query onMounted when suspended closes #56
Browse files Browse the repository at this point in the history
  • Loading branch information
logaretm committed Oct 9, 2020
1 parent e751d31 commit 27385b6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions packages/villus/src/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,15 +125,16 @@ function useQuery<TData = any, TVars = QueryVariables>(
): ThenableQueryComposable<TData> {
const normalizedOpts = normalizeOptions(opts, variables);
const api = _useQuery<TData, TVars>(normalizedOpts);
if (normalizedOpts.fetchOnMount) {
onMounted(() => {
onMounted(() => {
if (normalizedOpts.fetchOnMount) {
api.execute();
});
}
}
});

return {
...api,
async then(onFulfilled: (value: any) => any) {
normalizedOpts.fetchOnMount = false;
await api.execute();

return onFulfilled(api);
Expand Down

0 comments on commit 27385b6

Please sign in to comment.