Skip to content

Commit

Permalink
task(docs): Updates docs to include result description meta param [#1904
Browse files Browse the repository at this point in the history
]
  • Loading branch information
bbboydston committed Jan 17, 2022
1 parent 637b0ca commit 939e8ac
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions docs/rtk-query/api/createApi.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ export type QueryDefinition<
TagTypes,
ResultType,
QueryArg,
BaseQueryError<BaseQuery>
BaseQueryError<BaseQuery>,
BaseQueryMeta<BaseQuery>
>

keepUnusedDataFor?: number
Expand Down Expand Up @@ -228,7 +229,13 @@ export type MutationDefinition<

extraOptions?: BaseQueryExtraOptions<BaseQuery>

invalidatesTags?: ResultDescription<TagTypes, ResultType, QueryArg>
invalidatesTags?: ResultDescription<
TagTypes,
ResultType,
QueryArg,
BaseQueryError<BaseQuery>,
BaseQueryMeta<BaseQuery>
>

onQueryStarted?(
arg: QueryArg,
Expand Down
1 change: 1 addition & 0 deletions docs/rtk-query/usage-with-typescript.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,7 @@ When using the function notation, both the `providesTags` and `invalidatesTags`
- result: `ResultType` | `undefined` - The result returned by a successful query. The type corresponds with `ResultType` as [supplied to the built endpoint](#typing-query-and-mutation-endpoints). In the error case for a query, this will be `undefined`.
- error: `ErrorType` | `undefined` - The error returned by an errored query. The type corresponds with `Error` as [supplied to the `baseQuery` for the api](#typing-a-basequery). In the success case for a query, this will be `undefined`.
- arg: `QueryArg` - The argument supplied to the `query` property when the query itself is called. The type corresponds with `QueryArg` as [supplied to the built endpoint](#typing-query-and-mutation-endpoints).
- meta: `MetaType` | `undefined` - The optional `meta` value returned by `baseQuery`

A recommended use-case with `providesTags` when a query returns a list of items is to provide a tag for each item in the list using the entity ID, as well as a 'LIST' ID tag (see [Advanced Invalidation with abstract tag IDs](./usage/automated-refetching.mdx#advanced-invalidation-with-abstract-tag-ids)).

Expand Down
9 changes: 8 additions & 1 deletion docs/rtk-query/usage/automated-refetching.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,14 @@ _see also: [invalidatesTags API reference](../api/createApi.mdx#invalidatestags)

A _mutation_ can _invalidate_ specific cached data based on the tags. Doing so determines which cached data will be either refetched or removed from the cache.

The `invalidatesTags` argument can either be an array of `string` (such as `['Post']`), `{type: string, id?: string|number}` (such as `[{type: 'Post', id: 1}]`), or a callback that returns such an array. That function will be passed the result as the first argument, the response error as the second argument, and the argument originally passed into the `query` method as the third argument. Note that either the result or error arguments may be undefined based on whether the mutation was successful or not.
The `invalidatesTags` argument can either be an array of `string` (such as `['Post']`), `{type: string, id?: string|number}` (such as `[{type: 'Post', id: 1}]`), or a callback that returns such an array. That function will be passed:

1. the result as the first argument,
1. the response error as the second argument,
1. the argument originally passed into the `query` method as the third argument,
1. and any optional `meta` property resolved by `baseQuery`.

Note that either the result or error arguments may be undefined based on whether the mutation was successful or not.

## Cache tags

Expand Down

0 comments on commit 939e8ac

Please sign in to comment.