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