Open History to see the last commit
1---
2id: useMutationState
3title: useMutationState
4---
5β
6```ts
7function useMutationState<TResult>(
8 host: ReactiveControllerHost,
9 options?: MutationStateOptions<TResult>,
10queryClient?: QueryClient): MutationStateAccessor<TResult>;
11```
12β
13Defined in: [packages/lit-query/src/useMutationState.ts:186](https://github.com/TanStack/query/blob/main/packages/lit-query/src/useMutationState.ts#L186)
14β
15Creates a Lit reactive controller that selects state from matching mutations
16in the mutation cache.
17β
18When `options.filters` is a function, it is re-read during host updates so
19the selection can follow reactive host state. If `queryClient` is omitted,
20the controller resolves the client from the nearest connected
21`QueryClientProvider`.
22β
23## Type Parameters
24β
25### TResult
26β
27`TResult` = [`MutationState`](../interfaces/MutationState.md)\<`unknown`, `unknown`, `unknown`, `unknown`\>
28β
29## Parameters
30β
31### host
32β
33`ReactiveControllerHost`
34β
35The Lit reactive controller host that owns the mutation cache
36subscription.
37β
38### options?
39β
40[`MutationStateOptions`](../type-aliases/MutationStateOptions.md)\<`TResult`\> = `{}`
41β
42Mutation state filters and optional selector.
43β
44<a id="options-properties"></a>
45β
46#### `options` properties
47β
48| Property | Type | Description |
49| ------ | ------ | ------ |
50| <a id="options-property-filters"></a> `filters?` | [`Accessor`](../type-aliases/Accessor.md)\<[`MutationFilters`](../interfaces/MutationFilters.md)\> | Filters used to select mutations from the mutation cache. |
51| <a id="options-property-select"></a> `select?` | (`mutation`: [`Mutation`](../classes/Mutation.md)) => `TResult` | Maps each matching mutation to the value returned by the accessor. |
52β
53### queryClient?
54β
55[`QueryClient`](../classes/QueryClient.md)
56β
57Optional explicit query client. Provide this for
58controllers that should not resolve a client from Lit context.
59β
60## Returns
61β
62[`MutationStateAccessor`](../type-aliases/MutationStateAccessor.md)\<`TResult`\>
63β
64An accessor for the selected mutation state array.
65β
66## Example
67β
68```ts
69import { LitElement, html } from 'lit'
70import { useMutationState } from '@tanstack/lit-query'
71β
72class PendingUploads extends LitElement {
73 private readonly uploads = useMutationState(this, {
74 filters: { mutationKey: ['upload'], status: 'pending' },
75 select: (mutation) => mutation.state.variables as File,
76 })
77β
78 render() {
79 return html`<span>${this.uploads().length} uploads pending</span>`
80 }
81}
82```