forked from mirrors/thatmattlove-hyperglass
cancel running queries on component unmount
This commit is contained in:
parent
e23e1fb924
commit
9f6d16c28c
1 changed files with 10 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
|||
import { useEffect } from 'react';
|
||||
import { useQuery } from 'react-query';
|
||||
import { useConfig } from '~/context';
|
||||
import { fetchWithTimeout } from '~/util';
|
||||
|
|
@ -34,6 +35,15 @@ export function useLGQuery(query: TFormQuery): QueryObserverResult<TQueryRespons
|
|||
);
|
||||
return await res.json();
|
||||
}
|
||||
|
||||
// Cancel any still-running queries on unmount.
|
||||
useEffect(
|
||||
() => () => {
|
||||
controller.abort();
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return useQuery<TQueryResponse, Response | TQueryResponse | Error>(
|
||||
['/api/query/', query],
|
||||
runQuery,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue