Skip to content

Commit 4331b0e

Browse files
authored
Merge pull request #2993 from zvolcsey/master
2 parents 4383544 + 9f785ec commit 4331b0e

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

docs/rtk-query/api/created-api/api-slice-utils.mdx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,54 @@ React Hooks users will most likely never need to use this directly, as the `useP
228228
dispatch(api.util.prefetch('getPosts', undefined, { force: true }))
229229
```
230230

231+
### `selectInvalidatedBy`
232+
233+
#### Signature
234+
235+
```ts no-transpile
236+
function selectInvalidatedBy(
237+
state: RootState,
238+
tags: ReadonlyArray<TagDescription<string>>
239+
): Array<{
240+
endpointName: string
241+
originalArgs: any
242+
queryCacheKey: QueryCacheKey
243+
}>
244+
```
245+
246+
- **Parameters**
247+
- `state`: the root state
248+
- `tags`: a readonly array of invalidated tags, where the provided `TagDescription` is one of the strings provided to the [`tagTypes`](../createApi.mdx#tagtypes) property of the api. e.g.
249+
- `[TagType]`
250+
- `[{ type: TagType }]`
251+
- `[{ type: TagType, id: number | string }]`
252+
253+
#### Description
254+
255+
A function that can select query parameters to be invalidated.
256+
257+
The function accepts two arguments
258+
- the root state and
259+
- the cache tags to be invalidated.
260+
261+
It returns an array that contains
262+
- the endpoint name,
263+
- the original args and
264+
- the queryCacheKey.
265+
266+
#### Example
267+
268+
```ts no-transpile
269+
dispatch(api.util.selectInvalidatedBy(state, ['Post']))
270+
dispatch(api.util.selectInvalidatedBy(state, [{ type: 'Post', id: 1 }]))
271+
dispatch(
272+
api.util.selectInvalidatedBy(state, [
273+
{ type: 'Post', id: 1 },
274+
{ type: 'Post', id: 4 },
275+
])
276+
)
277+
```
278+
231279
### `invalidateTags`
232280

233281
#### Signature

0 commit comments

Comments
 (0)