useIsFetching
TheuseIsFetching hook returns the number of queries that are currently fetching. This is useful for showing a global loading indicator.
Import
Signature
Parameters
QueryFilters
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
useSyncExternalStoreto efficiently subscribe to query cache changes - Returns
0when 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