diff --git a/src/hooks/useQuery.ts b/src/hooks/useQuery.ts index 86d4e41413..607d5b2525 100644 --- a/src/hooks/useQuery.ts +++ b/src/hooks/useQuery.ts @@ -1,5 +1,5 @@ import { DocumentNode } from 'graphql'; -import { useEffect, useCallback, useContext, useRef, useState } from 'react'; +import { useCallback, useContext, useRef, useState } from 'react'; import { pipe, subscribe } from 'wonka'; import { Context } from '../context'; import { OperationContext, RequestPolicy } from '../types'; @@ -42,12 +42,6 @@ export const useQuery = ( data: undefined, }); - useEffect(() => { - return () => { - isMounted.current = false; - } - }, []); - const executeQuery = useCallback( (opts?: Partial) => { unsubscribe.current(); @@ -79,7 +73,11 @@ export const useQuery = ( // treats it as a normal effect useImmediateEffect(() => { executeQuery(); - return () => unsubscribe.current(); + + return () => { + isMounted.current = false; + unsubscribe.current(); + }; }, [executeQuery]); return [state, executeQuery];