0
Fork 0
mirror of https://github.com/TanStack/query.git synced 2026-11-16 22:50:20 +00:00
query/docs/framework/lit/reference/functions/useMutationState.md
Wonsuk Choi f38e6271b4
chore(*): update '@tanstack/typedoc-config' to v0.3.5 (#12035)
* chore(scripts/generate-docs): read type alias bodies whose type parameters have defaults

* chore(*): update '@tanstack/typedoc-config' to v0.3.5
2026-10-17 11:14:03 +09:00

2.5 KiB

id title
useMutationState useMutationState
function useMutationState<TResult = MutationState<unknown, unknown, unknown, unknown>>(
   host: ReactiveControllerHost,
   options?: MutationStateOptions<TResult>,
   queryClient?: QueryClient
): MutationStateAccessor<TResult>;

Defined in: packages/lit-query/src/useMutationState.ts:186

Creates a Lit reactive controller that selects state from matching mutations in the mutation cache.

When options.filters is a function, it is re-read during host updates so the selection can follow reactive host state. If queryClient is omitted, the controller resolves the client from the nearest connected QueryClientProvider.

Type Parameters

TResult

TResult = MutationState<unknown, unknown, unknown, unknown>

Parameters

host

ReactiveControllerHost

The Lit reactive controller host that owns the mutation cache subscription.

options?

MutationStateOptions<TResult> = {}

Mutation state filters and optional selector.

options properties

Property Type Description
filters? Accessor<MutationFilters> Filters used to select mutations from the mutation cache.
select? (mutation: Mutation) => TResult Maps each matching mutation to the value returned by the accessor.

queryClient?

QueryClient

Optional explicit query client. Provide this for controllers that should not resolve a client from Lit context.

Returns

MutationStateAccessor<TResult>

An accessor for the selected mutation state array.

Example

import { LitElement, html } from 'lit'
import { useMutationState } from '@tanstack/lit-query'

class PendingUploads extends LitElement {
  private readonly uploads = useMutationState(this, {
    filters: { mutationKey: ['upload'], status: 'pending' },
    select: (mutation) => mutation.state.variables as File,
  })

  render() {
    return html`<span>${this.uploads().length} uploads pending</span>`
  }
}