Skip to content
Source
Sign inSign up
TanStack/query

[docs] The `variables` is wrongly obtained in the "Mutation Filters" `predicate` example #8578

Send to my agent
Closedoleksandr-danylchenko(GitHub profile, opens in a new tab) opened this issue 2 comments

Describe the bug

In the Mutation Filter docs section, there's a following example:

// Filter mutations using a predicate function
await queryClient.isMutating({
  predicate: (mutation) => mutation.options.variables?.id === 1,
})

Unfortunately, the mutation.options.variables expression would yield an error, because the variables doesn't exist on the options! https://github.com/TanStack/query/blob/12d4542f250dfd1b88b7c5ff695a3ff87566b23f/packages/query-core/src/types.ts#L1038-L1072 Instead, it exists on the state: https://github.com/TanStack/query/blob/12d4542f250dfd1b88b7c5ff695a3ff87566b23f/packages/query-core/src/mutation.ts#L23-L38

Steps to reproduce

  1. Go to https://tanstack.com/query/v5/docs/framework/react/guides/filters#mutation-filters
  2. See the mentioned example for the predicate usage

Expected behavior

-predicate: (mutation) => mutation.options.variables?.id === 1,
+predicate: (mutation) => mutation.state.variables?.id === 1,

TanStack Query version

v5.64.1

TypeScript version

v5.7.3

  1. thanks, would you like to make a PR to fix the docs?

  2. TkDodo added labelsdocumentation

  3. TkDodo closed this

Sign in to join this conversation.