isLoading vs isPending vs isFetching in TanStack Query

IntermediateState management interview questionBy , updated 3 December 2026

Short answer

In TanStack Query, isPending means the query has no data yet. isFetching means the query function is running right now, and that includes background refetches. isLoading is both at once: the first fetch is in flight. Use isPending for a full skeleton, isFetching for a small "refreshing" hint, and isLoading when a query can sit disabled with no data. In v5, the old isLoading was renamed to isPending.

Two questions, two status fields

Every query has two separate status fields, and every flag comes from one of them or from both.

  • status is about the data. Do we have any? It is pending (no data yet), error or success.
  • fetchStatus is about the query function. Is it running? It is fetching, paused (it wanted to fetch but is offline) or idle.

The docs explain why both exist: background refetches and stale-while-revalidate make every combination possible. A query can be pending without fetching (it is disabled), and it can be success while fetching (a background refetch of stale data).

Flag True when Comes from
isPending No cached data, no placeholder data and no error status === 'pending'
isFetching The queryFn is running, first load or background fetchStatus === 'fetching'
isLoading The first fetch is in flight isPending && isFetching
isRefetching A background refetch is running isFetching && !isPending
isSuccess There is data and no error status === 'success'
isError The last fetch failed after its retries status === 'error'
isPaused It wanted to fetch but is paused fetchStatus === 'paused'

The same query over time

Take a products list with default options:

  1. First mount. No data, request running. isPending, isFetching and isLoading are all true.
  2. Data arrives. isSuccess is true; the other three are false.
  3. The user refocuses the tab. The data is stale, so it refetches in the background. isFetching and isRefetching are true. isPending and isLoading stay false, because data is on screen.
  4. The refetch finishes. Back to step 2 with fresh data.

That is why a full-page spinner tied to isFetching flashes on every window focus, and one tied to isPending does not.

Which flag to use where

function Products() {
  const { data, error, isPending, isError, isFetching } = useQuery({
    queryKey: ["products"],
    queryFn: fetchProducts,
  });

  if (isPending) return <ProductsSkeleton />;
  if (isError && !data) return <p role="alert">Could not load products: {error.message}</p>;

  return (
    <section aria-busy={isFetching}>
      {isFetching && <small>Refreshing</small>}
      <ProductList products={data} />
    </section>
  );
}
  • Skeleton or full spinner: isPending. There is nothing to show yet.
  • Subtle refresh hint: isFetching. Old data stays visible.
  • One indicator for the whole app: useIsFetching() returns how many queries are fetching, including background refetches, so a top-of-page bar can use it.

The isError && !data check matters because a failed background refetch sets status to error while the old data is still there. The docs split this case into isLoadingError (error, no data) and isRefetchError (error, data still shown), so you can keep the list visible and show a small warning instead of wiping the screen.

Disabled queries: why isLoading came back

A disabled query is pending from the start, because it has no data, but it is not fetching. With enabled: false, or a dependent query waiting for an id, isPending is true forever until something enables it.

const { data, isPending, isLoading } = useQuery({
  queryKey: ["user", userId],
  queryFn: () => fetchUser(userId),
  enabled: Boolean(userId),
});
// No userId yet: isPending true, isFetching false, isLoading false

If you render a spinner on isPending here, the user sees a spinner for a request that never started. isLoading is only true while the first request is actually running, so it is the better flag for disabled, lazy and dependent queries. The docs recommend it for exactly this case.

What changed in v5

In v4 the status value was loading and the flag was isLoading, and it meant "no data yet". v5 renamed both to pending and isPending. It then added a new isLoading defined as isPending && isFetching, which is what v4 called isInitialLoading. isInitialLoading is deprecated and will be removed in the next major version. Mutations changed the same way: useMutation returns isPending, not isLoading.

So code copied from a v4 tutorial that renders if (isLoading) still compiles in v5 but means something slightly different: it is now false for a disabled query with no data, and your component may fall through to code that expects data.

You can see both clocks in a from-scratch cache in Implement useQuery with caching, retries, and stale data and Build a mini React Query. The loading, error, empty and abort states are drilled in Handle every data-fetching state.

Common follow-up questions

Is isLoading the same in RTK Query?

Close, but the names differ. In RTK Query, isLoading means in flight with no data yet, and isFetching means in flight, maybe with older data. That matches TanStack Query's isLoading and isFetching. RTK Query has isUninitialized for a query that has not started, where TanStack Query reports isPending with an idle fetchStatus. See RTK Query vs TanStack Query.

How do I keep the old page visible while the next page loads?

Pass placeholderData: keepPreviousData (or a function returning the previous data). Placeholder data counts as data, so isPending stays false while page 2 loads, isFetching is true, and isPlaceholderData tells you the rows are from page 1.

Why is isPending true when nothing is loading?

The query is disabled or waiting on a dependency, so fetchStatus is idle. Check isLoading or fetchStatus instead.

When does isError turn true?

Only when a fetch has failed after all its retries, or when your select function throws. While the retries run, the query is still fetching and has no error yet, so a first load shows the skeleton, not the error message.

How does this relate to staleTime?

Stale data triggers background refetches, which set isFetching but not isPending. Raising staleTime means fewer of those. See staleTime vs gcTime.

Mistakes to avoid

  • Showing a full-page spinner on isFetching, which flashes on every focus and invalidation

  • Using isPending for a disabled or dependent query and showing a spinner that never ends

  • Following v4 examples in v5 code and reading isLoading as "no data yet"

  • Hiding cached data whenever isError is true, even though a failed background refetch leaves the old data in place

  • Guarding data with isLoading alone; a disabled query has isLoading false and data undefined, so the component crashes

Practise it in code

Interviewers rarely stop at the definition. These questions open in an editor with tests.

  1. Implement useQuery() with caching, retries, and stale dataMedium45 min
  2. Build a mini React Query: QueryClient, useQuery, prefix invalidation and garbage collectionHard60 min
  3. Handle every data-fetching state: loading, error with retry, empty results, no stale data and abortMedium35 min
  4. Build a TanStack Query-style useInfiniteQuery(): page params, fetchNextPage, hasNextPage, maxPages and refetchMedium50 min
  5. Build a TanStack Query-style useMutation(): lifecycle callbacks, optimistic updates, rollback and invalidationMedium50 min
  6. Load a list, then the selected item's details, without races: abort, ignore stale responses and cache by idMedium40 min