Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

matchMutation.md

57 lines1.8 KB

1---
2id: matchMutation
3title: matchMutation
4---
5​
6<!-- DO NOT EDIT: this page is autogenerated from the type comments -->
7​
8```ts
9function matchMutation(filters: MutationFilters, mutation: Mutation<any, any>): boolean;
10```
11​
12Defined in: [packages/query-core/src/utils.ts:269](https://github.com/TanStack/query/blob/main/packages/query-core/src/utils.ts#L269)
13​
14Checks whether a mutation matches the given [MutationFilters](../interfaces/MutationFilters.md).
15Every filter that is specified must match; filters that are left unspecified are ignored.
16If a `mutationKey` filter is provided but the mutation has no `mutationKey` of its own, it does not match.
17​
18## Parameters
19​
20### filters
21​
22[`MutationFilters`](../interfaces/MutationFilters.md)
23​
24The filters to check the mutation against.
25​
26<a id="filters-properties"></a>
27​
28#### `filters` properties
29​
30| Property | Type | Description |
31| ------ | ------ | ------ |
32| <a id="filters-property-exact"></a> `exact?` | `boolean` | Match mutation key exactly |
33| <a id="filters-property-mutationkey"></a> `mutationKey?` | readonly `unknown`[] | Include mutations matching this mutation key |
34| <a id="filters-property-predicate"></a> `predicate?` | (`mutation`: [`Mutation`](../classes/Mutation.md)\<`TData`, `TError`, `TVariables`, `TOnMutateResult`\>) => `boolean` | Include mutations matching this predicate function |
35| <a id="filters-property-status"></a> `status?` | `"error"` \| `"pending"` \| `"success"` \| `"idle"` | Filter by mutation status |
36​
37### mutation
38​
39[`Mutation`](../classes/Mutation.md)\<`any`, `any`\>
40​
41The mutation to check.
42​
43## Returns
44​
45`boolean`
46​
47`true` if the mutation matches every specified filter.
48​
49## Example
50​
51```ts
52const mutationCache = queryClient.getMutationCache()
53​
54const matchingMutations = mutationCache
55 .getAll()
56 .filter((mutation) => matchMutation({ mutationKey: ['addPost'] }, mutation))
57```