You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description:
prefetch thunk now returns an object with shape:
```ts
export interface PrefetchActionCreatorResult {
/**
* Returns a promise that **always** resolves to `undefined`
* when there are no pending requests initiated by input thunk.
*/
unwrap(): Promise<void>,
/**
* Cancels pending requests.
*/
abort(): void
}
```
-`options`: options to determine whether the request should be sent for a given situation:
172
182
-`ifOlderThan`: if specified, only runs the query if the difference between `new Date()` and the last`fulfilledTimeStamp` is greater than the given value (in seconds)
173
183
-`force`: if `true`, it will ignore the `ifOlderThan` value if it is set and the query will be run even if it exists in the cache.
174
-
184
+
-`keepSubscriptionFor`: how long in seconds before the data retrieved is considered unused;
185
+
defaults to `api.config.keepPrefetchSubscriptionsFor`.
175
186
#### Description
176
187
177
188
A Redux thunk action creator that can be used to manually trigger pre-fetching of data.
178
189
179
190
The thunk action creator accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), any relevant query arguments, and a set of options used to determine if the data actually should be re-fetched based on cache staleness.
180
191
192
+
The output is an object with methods:
193
+
-`unwrap`: returns a promise that resolves to `undefined` when there are no pending requests initiated by this thunk.
194
+
-`abort`: cancels pending requests.
195
+
181
196
React Hooks users will most likely never need to use this directly, as the `usePrefetch` hook will dispatch the thunk action creator result internally as needed when you call the prefetching function supplied by the hook.
Copy file name to clipboardExpand all lines: docs/rtk-query/usage/prefetching.mdx
+11-4
Original file line number
Diff line number
Diff line change
@@ -26,16 +26,23 @@ Similar to the [`useMutation`](./mutations) hook, the `usePrefetch` hook will no
26
26
It accepts two arguments: the first is the key of a query action that you [defined in your API service](../api/createApi#endpoints), and the second is an object of two optional parameters:
* The thunk accepts three arguments: the name of the endpoint we are updating (such as `'getPost'`), any relevant query arguments, and a set of options used to determine if the data actually should be re-fetched based on cache staleness.
176
177
*
178
+
* The output is an object with the following methods:
179
+
* - `unwrap`: returns a promise that resolves to `undefined` when there are no pending requests initiated by this thunk.
180
+
* - `abort`: cancels pending requests.
181
+
*
177
182
* React Hooks users will most likely never need to use this directly, as the `usePrefetch` hook will dispatch this thunk internally as needed when you call the prefetching function supplied by the hook.
* A Redux thunk action creator that, when dispatched, creates and applies a set of JSON diff/patch objects to the current state. This immediately updates the Redux state with those changes.
0 commit comments