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
feat(rtk-query): unsubscribe prefetched queries after configurable timer #1283
Closes#1283
Automatically removes prefetch subscriptions after configurable amount of time.
Description:
Prefetch subscription are now removed after `prefetchOptions.keepSubscriptionFor` if provided
or api.config.keepPrefetchSubscriptionsFor otherwise.
Api changes:
- adds `keepSubscriptionFor` to prefetchOptions
- adds `keepPrefetchSubscriptionsFor` to api.config (default 10s)
Internal changes:
- prefetch queries now have the same requestId and the same subscription key
* import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
139
+
* interface Post {
140
+
* id: number
141
+
* name: string
142
+
* }
143
+
* type PostsResponse = Post[]
144
+
*
145
+
* const api = createApi({
146
+
* baseQuery: fetchBaseQuery({ baseUrl: '/' }),
147
+
* keepPrefetchSubscriptionsFor: 5,
148
+
* endpoints: (build) => ({
149
+
* getPosts: build.query<PostsResponse, void>({
150
+
* query: () => 'posts',
151
+
* // highlight-start
152
+
* // highlight-end
153
+
* })
154
+
* })
155
+
* })
156
+
* ```
157
+
*/
158
+
keepPrefetchSubscriptionsFor?: number
129
159
/**
130
160
* Defaults to `false`. This setting allows you to control whether if a cached result is already available RTK Query will only serve a cached result, or if it should `refetch` when set to `true` or if an adequate amount of time has passed since the last successful query result.
131
161
* - `false` - Will not cause a query to be performed _unless_ it does not exist yet.
@@ -240,6 +270,7 @@ export function buildCreateApi<Modules extends [Module<any>, ...Module<any>[]]>(
0 commit comments