Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
dutziworks authored and markerikson committed Sep 24, 2023
1 parent bd7f3ba commit ca0b28e
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions docs/rtk-query/api/created-api/api-slice-utils.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Some of the TS types on this page are pseudocode to illustrate intent, as the ac
const updateQueryData = (
endpointName: string,
args: any,
updateRecipe: (draft: Draft<CachedState>) => void
updateRecipe: (draft: Draft<CachedState>) => void,
updateProvided?: boolean
) => ThunkAction<PatchCollection, PartialState, any, AnyAction>;

interface PatchCollection {
Expand All @@ -43,6 +44,7 @@ interface PatchCollection {
- `endpointName`: a string matching an existing endpoint name
- `args`: an argument matching that used for a previous query call, used to determine which cached dataset needs to be updated
- `updateRecipe`: an Immer `produce` callback that can apply changes to the cached state
- `updateProvided`: a boolean indicating whether the endpoint's provided tags should be re-calculated based on the updated cache. Defaults to `false`.

#### Description

Expand Down Expand Up @@ -155,14 +157,16 @@ await dispatch(
const patchQueryData = (
endpointName: string,
args: any
patches: Patch[]
patches: Patch[],
updateProvided?: boolean
) => ThunkAction<void, PartialState, any, AnyAction>;
```

- **Parameters**
- `endpointName`: a string matching an existing endpoint name
- `args`: a cache key, used to determine which cached dataset needs to be updated
- `patches`: an array of patches (or inverse patches) to apply to cached state. These would typically be obtained from the result of dispatching [`updateQueryData`](#updatequerydata)
- `updateProvided`: a boolean indicating whether the endpoint's provided tags should be re-calculated based on the updated cache. Defaults to `false`.

#### Description

Expand Down Expand Up @@ -229,42 +233,42 @@ dispatch(api.util.prefetch('getPosts', undefined, { force: true }))
```

### `selectInvalidatedBy`

#### Signature

```ts no-transpile
function selectInvalidatedBy(
state: RootState,
tags: ReadonlyArray<TagDescription<string>>
): Array<{
endpointName: string
originalArgs: any
queryCacheKey: QueryCacheKey
}>
function selectInvalidatedBy(
state: RootState,
tags: ReadonlyArray<TagDescription<string>>
): Array<{
endpointName: string
originalArgs: any
queryCacheKey: QueryCacheKey
}>
```

- **Parameters**
- `state`: the root state
- `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.
- `[TagType]`
- `[{ type: TagType }]`
- `[{ type: TagType, id: number | string }]`

#### Description

A function that can select query parameters to be invalidated.

The function accepts two arguments
- the root state and
- the cache tags to be invalidated.
- the root state and
- the cache tags to be invalidated.

It returns an array that contains
- the endpoint name,
- the original args and
- the queryCacheKey.
- the endpoint name,
- the original args and
- the queryCacheKey.

#### Example

```ts no-transpile
dispatch(api.util.selectInvalidatedBy(state, ['Post']))
dispatch(api.util.selectInvalidatedBy(state, [{ type: 'Post', id: 1 }]))
Expand Down

0 comments on commit ca0b28e

Please sign in to comment.