Open History to see the last commit
1---
2id: background-fetching-indicators
3title: Background Fetching Indicators
4---
5β
6A query's `status === 'loading'` state is sufficient enough to show the initial hard-loading state for a query, but sometimes you may want to display an additional indicator that a query is refetching in the background. To do this, queries also supply you with an `isFetching` boolean that you can use to show that it's in a fetching state, regardless of the state of the `status` variable:
7β
8```tsx
9function Todos() {
10 const { status, data: todos, error, isFetching } = useQuery(
11 ['todos'],
12 fetchTodos
13 )
14β
15 return status === 'loading' ? (
16 <span>Loading...</span>
17 ) : status === 'error' ? (
18 <span>Error: {error.message}</span>
19 ) : (
20 <>
21 {isFetching ? <div>Refreshing...</div> : null}
22β
23 <div>
24 {todos.map(todo => (
25 <Todo todo={todo} />
26 ))}
27 </div>
28 </>
29 )
30}
31```
32β
33# Displaying Global Background Fetching Loading State
34β
35In addition to individual query loading states, if you would like to show a global loading indicator when **any** queries are fetching (including in the background), you can use the `useIsFetching` hook:
36β
37```tsx
38import { useIsFetching } from '@tanstack/react-query'
39β
40function GlobalLoadingIndicator() {
41 const isFetching = useIsFetching()
42β
43 return isFetching ? (
44 <div>Queries are fetching in the background...</div>
45 ) : null
46}
47```