File tree Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Expand file tree Collapse file tree 3 files changed +13
-2
lines changed Original file line number Diff line number Diff line change 1
1
import { useMemo } from 'react' ;
2
2
3
- import { useInfiniteQuery } from '@tanstack/react-query' ;
3
+ import { skipToken , useInfiniteQuery } from '@tanstack/react-query' ;
4
4
import type { InfiniteData , InfiniteQueryObserverOptions } from '@tanstack/react-query' ;
5
5
6
6
import type {
@@ -16,6 +16,7 @@ import type {
16
16
} from '../../../core' ;
17
17
import { useRefetchInterval } from '../../hooks/useRefetchInterval' ;
18
18
import { normalizeStatus } from '../../utils/normalizeStatus' ;
19
+ import { warnDisabledRefetch } from '../../utils/warnDisabledRefetch' ;
19
20
20
21
import type { AnyInfiniteQueryDataSource , InfiniteQueryObserverExtendedOptions } from './types' ;
21
22
import { composeOptions } from './utils' ;
@@ -63,11 +64,14 @@ export const useInfiniteQueryData = <TDataSource extends AnyInfiniteQueryDataSou
63
64
[ state . data ] ,
64
65
) ;
65
66
67
+ const isDisabled = composedOptions . enabled === false || composedOptions . queryFn === skipToken ;
68
+
66
69
return {
67
70
...state ,
68
71
status : normalizeStatus ( state . status , state . fetchStatus ) ,
69
72
data : transformedData ,
70
73
originalStatus : state . status ,
71
74
originalData : state . data ,
75
+ refetch : isDisabled ? warnDisabledRefetch : state . refetch ,
72
76
} as DataSourceState < TDataSource > ;
73
77
} ;
Original file line number Diff line number Diff line change 1
- import { type QueryObserverOptions , useQuery } from '@tanstack/react-query' ;
1
+ import { type QueryObserverOptions , skipToken , useQuery } from '@tanstack/react-query' ;
2
2
3
3
import type {
4
4
DataSourceContext ,
@@ -12,6 +12,7 @@ import type {
12
12
} from '../../../core' ;
13
13
import { useRefetchInterval } from '../../hooks/useRefetchInterval' ;
14
14
import { normalizeStatus } from '../../utils/normalizeStatus' ;
15
+ import { warnDisabledRefetch } from '../../utils/warnDisabledRefetch' ;
15
16
16
17
import type { AnyPlainQueryDataSource , QueryObserverExtendedOptions } from './types' ;
17
18
import { composeOptions } from './utils' ;
@@ -52,9 +53,12 @@ export const usePlainQueryData = <TDataSource extends AnyPlainQueryDataSource>(
52
53
const composedOptions = usePlainQueryDataOptions ( extendedOptions ) ;
53
54
const state = useQuery ( composedOptions ) ;
54
55
56
+ const isDisabled = composedOptions . enabled === false || composedOptions . queryFn === skipToken ;
57
+
55
58
return {
56
59
...state ,
57
60
status : normalizeStatus ( state . status , state . fetchStatus ) ,
58
61
originalStatus : state . status ,
62
+ refetch : isDisabled ? warnDisabledRefetch : state . refetch ,
59
63
} as DataSourceState < TDataSource > ;
60
64
} ;
Original file line number Diff line number Diff line change
1
+ export const warnDisabledRefetch = ( ) => {
2
+ console . warn ( 'Disabled refetch is called' ) ;
3
+ } ;
You can’t perform that action at this time.
0 commit comments