Skip to content

Commit

Permalink
Merge new useEffect and useImmediateEffect
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jun 3, 2019
1 parent 3242444 commit 47a7d62
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -42,12 +42,6 @@ export const useQuery = <T = any, V = object>(
data: undefined,
});

useEffect(() => {
return () => {
isMounted.current = false;
}
}, []);

const executeQuery = useCallback(
(opts?: Partial<OperationContext>) => {
unsubscribe.current();
Expand Down Expand Up @@ -79,7 +73,11 @@ export const useQuery = <T = any, V = object>(
// treats it as a normal effect
useImmediateEffect(() => {
executeQuery();
return () => unsubscribe.current();

return () => {
isMounted.current = false;
unsubscribe.current();
};
}, [executeQuery]);

return [state, executeQuery];
Expand Down

0 comments on commit 47a7d62

Please sign in to comment.