框架
版本

useIsMutating

useIsMutating 是一个可选的 Hook,它返回你的应用程序正在获取的 number 个突变数量(对于应用程序范围内的加载指示器很有用)。

tsx
import { useIsMutating } from '@tanstack/react-query'
// How many mutations are fetching?
const isMutating = useIsMutating()
// How many mutations matching the posts prefix are fetching?
const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })
import { useIsMutating } from '@tanstack/react-query'
// How many mutations are fetching?
const isMutating = useIsMutating()
// How many mutations matching the posts prefix are fetching?
const isMutatingPosts = useIsMutating({ mutationKey: ['posts'] })

选项

  • filters?: MutationFilters: 突变过滤器
  • queryClient?: QueryClient,
    • 使用此项可使用自定义的 QueryClient。否则,将使用来自最近上下文的 QueryClient。

返回值

  • isMutating: number
    • 将是你的应用程序当前正在获取的 number 个突变数量。