Skip to content

Commit b646eb4

Browse files
akashshyamdevLenz Weber
andauthored
fix(useLazyQuery): added docs for preferCache option (#1541)
Co-authored-by: Lenz Weber <[email protected]>
1 parent a44511e commit b646eb4

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
@@ -181,17 +181,30 @@ export type UseLazyQueryLastPromiseInfo<
181181
* - Re-renders as the request status changes and data becomes available
182182
* - 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
183183
*
184+
* #### Note
185+
*
186+
* 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.
184187
*/
185188
export type UseLazyQuery<D extends QueryDefinition<any, any, any, any>> = <
186189
R = UseQueryStateDefaultResult<D>
187190
>(
188191
options?: SubscriptionOptions & Omit<UseQueryStateOptions<D, R>, 'skip'>
189192
) => [
190-
(arg: QueryArgFrom<D>) => void,
193+
LazyQueryTrigger<D>,
191194
UseQueryStateResult<D, R>,
192195
UseLazyQueryLastPromiseInfo<D>
193196
]
194197

198+
export type LazyQueryTrigger<D extends QueryDefinition<any, any, any, any>> = {
199+
/**
200+
* Triggers a lazy query.
201+
*
202+
* By default, this will start a new request even if there is already a value in the cache.
203+
* 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`.
204+
*/
205+
(arg: QueryArgFrom<D>, preferCacheValue?: boolean): void
206+
}
207+
195208
/**
196209
* A React hook similar to [`useQuerySubscription`](#usequerysubscription), but with manual control over when the data fetching occurs.
197210
*

0 commit comments

Comments
 (0)