-
-
Couldn't load subscription status.
- Fork 1.2k
Description
There is cases when abort might be useful to use while using useQuery hook to stop chain of queryFn requests, polling or long running tasks.
Proposal
Expose abort method from useQuery hook same as we do with "refetch"
Use case
Inside queryFn I have a polling which submit the task (call A - once) and then poll task result by task id (call B - multiple with internal). Basically I need to abort data polling when it's not needed any more, for example on component unmount.
Currently we have to use useLazyQuery to achieve this:
const [trigger, { data, error }] = useLazyQuery();
useEffect(() => {
const { abort, unsubscribe } = trigger();
return () => {
abort();
unsubscribe();
}
}, [])
What we want to achieve:
const { abort, data, error } = useQuery();
useEffect(() => abort, [])
Or ideally it would be great if abort would happen by default on unmount internally so we don't have to do this manually... or controlled by additional option prop like "abortOnUnmount: boolean, abortOnArgsChange: boolean"