@@ -63,7 +63,7 @@ import { UNINITIALIZED_VALUE } from './constants'
6363import type { ReactHooksModuleOptions } from './module'
6464import { useStableQueryArgs } from './useSerializedStableValue'
6565import { useShallowStableValue } from './useShallowStableValue'
66- import { InfiniteQueryDirection } from '../core/apiState'
66+ import type { InfiniteQueryDirection } from '../core/apiState'
6767
6868// Copy-pasted from React-Redux
6969const canUseDOM = ( ) =>
@@ -857,7 +857,9 @@ export type TypedUseInfiniteQuerySubscription<
857857
858858export type UseInfiniteQuerySubscriptionResult <
859859 D extends InfiniteQueryDefinition < any , any , any , any , any > ,
860- > = LazyInfiniteQueryTrigger < D >
860+ > = Pick < InfiniteQueryActionCreatorResult < D > , 'refetch' > & {
861+ trigger : LazyInfiniteQueryTrigger < D >
862+ }
861863
862864/**
863865 * Helper type to manually type the result
@@ -922,15 +924,13 @@ export type UseInfiniteQuerySubscription<
922924> = (
923925 arg : QueryArgFrom < D > | SkipToken ,
924926 options ?: UseInfiniteQuerySubscriptionOptions < D > ,
925- ) => readonly [
926- LazyInfiniteQueryTrigger < D > ,
927- QueryArgFrom < D > | UninitializedValue ,
928- ]
927+ ) => UseInfiniteQuerySubscriptionResult < D >
929928
930929export type UseInfiniteQueryHookResult <
931930 D extends InfiniteQueryDefinition < any , any , any , any , any > ,
932931 R = UseInfiniteQueryStateDefaultResult < D > ,
933- > = UseInfiniteQueryStateResult < D , R >
932+ > = UseInfiniteQueryStateResult < D , R > &
933+ Pick < UseInfiniteQuerySubscriptionResult < D > , 'refetch' >
934934
935935export type UseInfiniteQueryStateOptions <
936936 D extends InfiniteQueryDefinition < any , any , any , any , any > ,
@@ -1000,8 +1000,6 @@ export type UseInfiniteQueryStateOptions<
10001000 * ```
10011001 */
10021002 selectFromResult ?: InfiniteQueryStateSelector < R , D >
1003- // TODO: This shouldn't be any
1004- trigger ?: any
10051003}
10061004
10071005export type UseInfiniteQueryStateResult <
@@ -1906,14 +1904,29 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
19061904 }
19071905 } , [ ] )
19081906
1909- return useMemo ( ( ) => [ trigger , arg ] as const , [ trigger , arg ] )
1907+ return useMemo (
1908+ ( ) => ( {
1909+ trigger,
1910+ /**
1911+ * A method to manually refetch data for the query
1912+ */
1913+ refetch : ( ) => {
1914+ if ( ! promiseRef . current )
1915+ throw new Error (
1916+ 'Cannot refetch a query that has not been started yet.' ,
1917+ )
1918+ return promiseRef . current ?. refetch ( )
1919+ } ,
1920+ } ) ,
1921+ [ trigger ] ,
1922+ )
19101923 }
19111924
19121925 const useInfiniteQueryState : UseInfiniteQueryState < any > = (
19131926 arg : any ,
1914- { skip = false , selectFromResult, trigger } = { } ,
1927+ { skip = false , selectFromResult } = { } ,
19151928 ) => {
1916- const { select, initiate } = api . endpoints [
1929+ const { select } = api . endpoints [
19171930 name
19181931 ] as unknown as ApiEndpointInfiniteQuery <
19191932 InfiniteQueryDefinition < any , any , any , any , any > ,
@@ -1980,13 +1993,12 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
19801993 useInfiniteQueryState,
19811994 useInfiniteQuerySubscription,
19821995 useInfiniteQuery ( arg , options ) {
1983- const [ trigger ] = useInfiniteQuerySubscription ( arg , options )
1996+ const { trigger, refetch } = useInfiniteQuerySubscription ( arg , options )
19841997 const queryStateResults = useInfiniteQueryState ( arg , {
19851998 selectFromResult :
19861999 arg === skipToken || options ?. skip
19872000 ? undefined
19882001 : noPendingQueryStateSelector ,
1989- trigger,
19902002 ...options ,
19912003 } )
19922004
@@ -2023,8 +2035,13 @@ export function buildHooks<Definitions extends EndpointDefinitions>({
20232035 } , [ trigger , arg ] )
20242036
20252037 return useMemo (
2026- ( ) => ( { ...queryStateResults , fetchNextPage, fetchPreviousPage } ) ,
2027- [ queryStateResults , fetchNextPage , fetchPreviousPage ] ,
2038+ ( ) => ( {
2039+ ...queryStateResults ,
2040+ fetchNextPage,
2041+ fetchPreviousPage,
2042+ refetch,
2043+ } ) ,
2044+ [ queryStateResults , fetchNextPage , fetchPreviousPage , refetch ] ,
20282045 )
20292046 } ,
20302047 }
0 commit comments