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 d169ee8778
docs(*): add property tables and overload overviews to reference pages and keep declared alias names (#11758)
* docs(*): add parameter and result property tables to reference function pages and an overview to overloaded ones

* docs(*): link to the base type's properties when a parameter or result type has no property table

* docs(framework/*/reference): regenerate reference docs

* docs(framework/*/reference): regenerate reference docs

* chore(scripts/generate-docs): restore the 'dirname' import that the merge dropped

* docs(framework/*/reference): regenerate reference docs

* docs(scripts/generate-docs): label overloads in the overview with their declared parameter and return types

* docs(framework/*/reference): regenerate reference docs

* docs(scripts/generate-docs): convert declared intersection types from the source so signatures keep their alias names

* docs(framework/*/reference): regenerate reference docs

* docs(scripts/generate-docs): reword a comment to avoid the unknown word 'inlines'

* docs(scripts/generate-docs): skip a parameter table on overloaded pages when its heading is missing
2026-10-06 02:38:27 +09:00

2.4 KiB

id title
useMutationState useMutationState
function useMutationState<TResult>(
   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>`
  }
}