Skip to content

Commit 7e6db78

Browse files
committed
feat: add isPrefetch property in query action
1 parent fd24f6f commit 7e6db78

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

packages/toolkit/src/query/core/buildInitiate.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type StartQueryActionCreator<
5858
> = (
5959
arg: QueryArgFrom<D>,
6060
options?: StartQueryActionCreatorOptions,
61+
isPrefetch?: boolean
6162
) => ThunkAction<QueryActionCreatorResult<D>, any, any, UnknownAction>
6263

6364
export type QueryActionCreatorResult<
@@ -302,6 +303,7 @@ You must add the middleware for RTK-Query to function correctly!`,
302303
subscriptionOptions,
303304
[forceQueryFnSymbol]: forceQueryFn,
304305
} = {},
306+
isPrefetch
305307
) =>
306308
(dispatch, getState) => {
307309
const queryCacheKey = serializeQueryArgs({
@@ -319,6 +321,7 @@ You must add the middleware for RTK-Query to function correctly!`,
319321
originalArgs: arg,
320322
queryCacheKey,
321323
[forceQueryFnSymbol]: forceQueryFn,
324+
isPrefetch
322325
})
323326
const selector = (
324327
api.endpoints[endpointName] as ApiEndpointQuery<any, any>

packages/toolkit/src/query/core/buildThunks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ export interface QueryThunkArg
112112
type: 'query'
113113
originalArgs: unknown
114114
endpointName: string
115+
isPrefetch?: boolean
115116
}
116117

117118
export interface MutationThunkArg {
@@ -613,6 +614,7 @@ In the case of an unhandled error, no tags will be "provided" or "invalidated".`
613614
(api.endpoints[endpointName] as ApiEndpointQuery<any, any>).initiate(
614615
arg,
615616
{ forceRefetch: force },
617+
true
616618
)
617619
const latestStateValue = (
618620
api.endpoints[endpointName] as ApiEndpointQuery<any, any>

0 commit comments

Comments
 (0)