Skip to content

Commit b4d940e

Browse files
akashshyamdevLenz Weber
authored andcommitted
fix(useLazyQuery): added docs for preferCache option (#1541)
Co-authored-by: Lenz Weber <lenz.weber@mayflower.de>
1 parent 38a9316 commit b4d940e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

packages/toolkit/src/query/react/buildHooks.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,17 +179,30 @@ export type UseLazyQueryLastPromiseInfo<
179179
* - Re-renders as the request status changes and data becomes available
180180
* - Accepts polling/re-fetching options to trigger automatic re-fetches when the corresponding criteria is met and the fetch has been manually called at least once
181181
*
182+
* #### Note
183+
*
184+
* When the trigger function returned from a LazyQuery, it always initiates a new request to the server even if there is cached data. Set `preferCacheValue`(the second argument to the function) as true if you want it to use cache.
182185
*/
183186
export type UseLazyQuery<D extends QueryDefinition<any, any, any, any>> = <
184187
R = UseQueryStateDefaultResult<D>
185188
>(
186189
options?: SubscriptionOptions & Omit<UseQueryStateOptions<D, R>, 'skip'>
187190
) => [
188-
(arg: QueryArgFrom<D>) => void,
191+
LazyQueryTrigger<D>,
189192
UseQueryStateResult<D, R>,
190193
UseLazyQueryLastPromiseInfo<D>
191194
]
192195

196+
export type LazyQueryTrigger<D extends QueryDefinition<any, any, any, any>> = {
197+
/**
198+
* Triggers a lazy query.
199+
*
200+
* By default, this will start a new request even if there is already a value in the cache.
201+
* If you want to use the cache value and only start a request if there is no cache value, set the second argument to `true`.
202+
*/
203+
(arg: QueryArgFrom<D>, preferCacheValue?: boolean): void
204+
}
205+
193206
/**
194207
* A React hook similar to [`useQuerySubscription`](#usequerysubscription), but with manual control over when the data fetching occurs.
195208
*

0 commit comments

Comments
 (0)