-
Notifications
You must be signed in to change notification settings - Fork 0
/
useSimpleParameterlessAutoRefreshQuery.ts
42 lines (40 loc) · 1.33 KB
/
useSimpleParameterlessAutoRefreshQuery.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import {
AutoRefreshOptions,
useSimpleAutoRefreshQuery,
} from './useSimpleAutoRefreshQuery'
import { UseSimpleQueryProps, UseSimpleQueryReturn } from './useSimpleQuery'
export type UseSimpleParameterlessAutoRefreshQueryProps<TResult> = Pick<
UseSimpleQueryProps<undefined, TResult>,
'query' | 'onResultReceived' | 'onLoadingChange'
> &
AutoRefreshOptions
/**
* @deprecated
*
* Performs a query on mount and repeats the query according to `refreshInterval`.
* Use this when `query` doesn't depend on any outside variables, e.g. props.
*
* Example:
* ```
* const { doQuery, doQueryAsync } = useParameterlessAutoRefreshQuery<WorkDocDto>({
* query: api.workDoc.getcount,
* onResultReceived: (count) => {
* setCount(count)
* dispatch(setShowBackendUnreachableAlert(false))
* },
* refreshInterval: moment.duration(1, 'minute'),
* onConnectionError: () => dispatch(setShowBackendUnreachableAlert(true))
* })
* ```
*
* @typeParam TResult the type returned by the query
*/
export function useSimpleParameterlessAutoRefreshQuery<TResult>(
props: UseSimpleParameterlessAutoRefreshQueryProps<TResult>
): UseSimpleQueryReturn {
return useSimpleAutoRefreshQuery<undefined, TResult>({
...props,
queryParams: undefined,
shouldQueryImmediately: () => true,
})
}