@@ -44,12 +44,23 @@ interface EndpointDefinitionWithQuery<
44
44
*
45
45
* const api = createApi({
46
46
* baseQuery: fetchBaseQuery({ baseUrl: '/' }),
47
+ * tagTypes: ['Post'],
47
48
* endpoints: (build) => ({
48
49
* getPosts: build.query<PostsResponse, void>({
49
50
* // highlight-start
50
51
* query: () => 'posts',
51
52
* // highlight-end
52
- * })
53
+ * }),
54
+ * addPost: build.mutation<Post, Partial<Post>>({
55
+ * // highlight-start
56
+ * query: (body) => ({
57
+ * url: `posts`,
58
+ * method: 'POST',
59
+ * body,
60
+ * }),
61
+ * // highlight-end
62
+ * invalidatesTags: [{ type: 'Post', id: 'LIST' }],
63
+ * }),
53
64
* })
54
65
* })
55
66
* ```
@@ -433,20 +444,37 @@ export interface QueryExtraOptions<
433
444
* with `serializeQueryArgs` returning a fixed cache key and a `merge` callback
434
445
* set to add incoming data to the cache entry each time.
435
446
*
436
- * Example:
447
+ * @example
437
448
*
438
449
* ```ts
439
- * forceRefetch({currentArg, previousArg}) {
440
- * // Assume these are page numbers
441
- * return currentArg !== previousArg
442
- * },
443
- * serializeQueryArgs({endpointName}) {
444
- * return endpointName
445
- * },
446
- * merge(currentCacheData, responseData) {
447
- * currentCacheData.push(...responseData)
450
+ * // codeblock-meta title="forceRefresh: pagination"
451
+ *
452
+ * import { createApi, fetchBaseQuery, defaultSerializeQueryArgs } from '@reduxjs/toolkit/query/react'
453
+ * interface Post {
454
+ * id: number
455
+ * name: string
448
456
* }
449
457
*
458
+ * createApi({
459
+ * baseQuery: fetchBaseQuery({ baseUrl: '/' }),
460
+ * endpoints: (build) => ({
461
+ * listItems: build.query<string[], number>({
462
+ * query: (pageNumber) => `/listItems?page=${pageNumber}`,
463
+ * // Only have one cache entry because the arg always maps to one string
464
+ * serializeQueryArgs: ({ endpointName }) => {
465
+ * return endpointName
466
+ * },
467
+ * // Always merge incoming data to the cache entry
468
+ * merge: (currentCache, newItems) => {
469
+ * currentCache.push(...newItems)
470
+ * },
471
+ * // Refetch when the page arg changes
472
+ * forceRefetch({ currentArg, previousArg }) {
473
+ * return currentArg !== previousArg
474
+ * },
475
+ * }),
476
+ * }),
477
+ *})
450
478
* ```
451
479
*/
452
480
forceRefetch ?( params : {
0 commit comments