Skip to main content

useIsFetching

The useIsFetching hook returns the number of queries that are currently fetching. This is useful for showing a global loading indicator.

Import

Signature

Parameters

QueryFilters
Optional filters to narrow down which queries to count
QueryKey
Filter by query key
boolean
If true, only match queries with the exact query key
(query: Query) => boolean
Custom predicate function to filter queries
'active' | 'inactive' | 'all'
Filter by query type
boolean
Filter by stale state
QueryClient
Optional QueryClient instance. If not provided, uses the context client.

Returns

number
The number of queries currently fetching that match the filters

Examples

Global Loading Indicator

In App Layout

With Specific Query Filter

Multiple Indicators

With Exact Matching

With Custom Predicate

Showing Count

Combined with State

Delayed Indicator

Filter by Type

Notes

  • The hook uses useSyncExternalStore to efficiently subscribe to query cache changes
  • Returns 0 when no queries are fetching
  • Updates automatically when queries start or stop fetching
  • Can be used multiple times with different filters in the same component
  • Useful for implementing global or section-specific loading indicators
  • The count includes all queries that match the filters, including background refetches
  • Does not cause re-renders unless the count actually changes