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

useMutationState.md

35 lines1.1 KB

1---
2id: useMutationState
3title: useMutationState
4---
5​
6`useMutationState` is a hook that gives you access to all mutations in the `MutationCache`. You can pass `filters` to it to narrow down your mutations, and `select` to transform the mutation state.
7​
8```tsx
9import { useMutationState } from '@tanstack/react-query'
10// Get all variables of all running mutations
11const variables = useMutationState({
12 filters: { status: 'pending' },
13 select: (mutation) => mutation.state.variables,
14})
15​
16// Get all data of all "post" mutations
17const data = useMutationState({
18 filters: { mutationKey: ['posts'] },
19 select: (mutation) => mutation.state.data,
20})
21```
22​
23**Options**
24​
25- `options`
26 - `filters?: MutationFilters`: [Mutation Filters](../guides/filters#mutation-filters)
27 - `select?: (mutation: Mutation) => TResult`
28 - Use this to transform the mutation state.
29- `queryClient?: QueryClient`,
30 - Use this to use a custom QueryClient. Otherwise, the one from the nearest context will be used.
31​
32**Returns**
33​
34- `Array<TResult>`
35 - Will be an Array of whatever `select` returns for each matching mutation.