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