useIsFetching
useIsFetching
是一个可选的钩子,它返回您的应用程序在后台加载或获取查询的 number(对于应用程序范围的加载指示器很有用)。
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"] });
Options(选项)
filters?: QueryFilters
: 查询过滤器context?: React.Context<QueryClient | undefined>
- 使用它来使用自定义的 React Query 上下文。否则,将使用 defaultContext
Returns(返回值)
isFetching: number
- 将是您的应用程序当前在后台加载或获取的查询的 number