Open History to see the last commit
1---
2id: useMutationState
3title: useMutationState
4---
5β
6```ts
7function useMutationState<TResult>(
8 host,
9 options,
10queryClient?): MutationStateAccessor<TResult>;
11```
12β
13Defined in: [packages/lit-query/src/useMutationState.ts:192](https://github.com/TanStack/query/blob/main/packages/lit-query/src/useMutationState.ts#L192)
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`\<`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### queryClient?
45β
46`QueryClient`
47β
48Optional explicit query client. Provide this for
49controllers that should not resolve a client from Lit context.
50β
51## Returns
52β
53[`MutationStateAccessor`](../type-aliases/MutationStateAccessor.md)\<`TResult`\>
54β
55An accessor for the selected mutation state array.
56β
57## Example
58β
59```ts
60import { LitElement, html } from 'lit'
61import { useMutationState } from '@tanstack/lit-query'
62β
63class PendingUploads extends LitElement {
64 private readonly uploads = useMutationState(this, {
65 filters: { mutationKey: ['upload'], status: 'pending' },
66 select: (mutation) => mutation.state.variables as File,
67 })
68β
69 render() {
70 return html`<span>${this.uploads().length} uploads pending</span>`
71 }
72}
73```