Skip to content

Commit

Permalink
Fix useImmediateEffect teardown
Browse files Browse the repository at this point in the history
  • Loading branch information
kitten committed Jun 3, 2019
1 parent 7c97dd9 commit 1ca0d9f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/hooks/useImmediateEffect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum EffectState {
type Effect = () => void | (() => void);

/** This executes an effect immediately on initial render and then treats it as a normal effect */
export const useImmediateEffect = (effect: Effect) => {
export const useImmediateEffect = (effect: Effect, changes?: any[]) => {
const state = useRef(EffectState.BeforeMount);

useEffect(() => {
Expand Down
5 changes: 4 additions & 1 deletion src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export const useQuery = <T = any, V = object>(

// Calls executeQuery on initial render immediately, then
// treats it as a normal effect
useImmediateEffect(executeQuery);
useImmediateEffect(() => {
executeQuery();
return () => unsubscribe.current();
}, [executeQuery]);

return [state, executeQuery];
};

0 comments on commit 1ca0d9f

Please sign in to comment.