Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
Reset promiseRef on useQuery/Mutation hooks (#173)
Browse files Browse the repository at this point in the history
* Reset the ref on unmount in the cleanup callbacks
  • Loading branch information
msutkowski authored Mar 16, 2021
1 parent ef42089 commit e7cbf48
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/react-hooks/buildHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,11 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
]);

useEffect(() => {
return () => void promiseRef.current?.unsubscribe();
return () => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
promiseRef.current?.unsubscribe();
promiseRef.current = undefined;
};
}, []);

return useMemo(
Expand Down Expand Up @@ -280,7 +284,13 @@ export function buildHooks<Definitions extends EndpointDefinitions>({

const promiseRef = useRef<MutationActionCreatorResult<any>>();

useEffect(() => () => void promiseRef.current?.unsubscribe(), []);
useEffect(() => {
return () => {
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
promiseRef.current?.unsubscribe();
promiseRef.current = undefined;
};
}, []);

const triggerMutation = useCallback(
function (args) {
Expand Down

0 comments on commit e7cbf48

Please sign in to comment.