in tanstack query, how do I find if a mutation has already run once?
Same as title.
8 Replies
fair-roseOP•12mo ago
or do i have to use something like onSuccess and update another state?
exotic-emerald•12mo ago
Would this suffice for your needs?
https://tanstack.com/query/latest/docs/framework/react/reference/useMutationState
useMutationState | TanStack Query React Docs
useMutationState is a hook that gives you access to all mutations in the MutationCache. You can pass filters to it to narrow down your mutations, and select to transform the mutation state.
Example 1: Get all variables of all running mutations
fair-roseOP•12mo ago
Yep it is.
Another question: is it possible for a use query to disable itself?
Use case: I deploy a background job on page load and then use query with a small refetchInterval to monitor job's status. When the job is completed, I want to disable the query
typical-coral•12mo ago
you want
refetchInterval
to be a functionfair-roseOP•12mo ago
What needs to be returned from the function to disable it?
false
?typical-coral•12mo ago
yes
fair-roseOP•12mo ago
How do i extract
data
from Query
type?metropolitan-bronze•12mo ago
I use a helper type for this: