Framework
Version

useIsFetching

useIsFetching 是一个可选的 Hook,返回 number 应用程序正在加载或在后台获取的查询数量(对于应用程序范围内的加载指示器很有用)。

tsx
import { useIsFetching } from '@tanstack/react-query'
// How many queries are fetching?
const isFetching = useIsFetching()
// How many queries matching the posts prefix are fetching?
const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })
import { useIsFetching } from '@tanstack/react-query'
// How many queries are fetching?
const isFetching = useIsFetching()
// How many queries matching the posts prefix are fetching?
const isFetchingPosts = useIsFetching({ queryKey: ['posts'] })

选项

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

返回值

  • isFetching: number
    • 将是 number 您的应用程序当前正在加载或在后台获取的查询数量。