Skip to main content
Network Mode controls how TanStack Query behaves when the device is online or offline. This is crucial for building applications that work in unreliable network conditions.

Network Modes

TanStack Query supports three network modes:
Queries and mutations only run when the device is online.
Behavior:
  • Pauses queries when offline
  • Resumes automatically when back online
  • Shows fetchStatus: 'paused' while offline

Default Network Mode

The default network mode is 'online':

Online/Offline Detection

TanStack Query uses the OnlineManager to detect network state:
By default, TanStack Query uses window.addEventListener('online') and window.addEventListener('offline') for detection.

Custom Online Detection

Override the default online detection:

Network Mode with Queries

Online Mode (Default)

Always Mode

Offline First Mode

Network Mode with Mutations

Mutations also respect network mode:

Paused State

When queries are paused, they have a special status:
A query can be status: 'pending' but fetchStatus: 'paused' when offline with no cached data.

Handling Paused Queries

Show appropriate UI when queries are paused:

Resume on Reconnect

Queries automatically resume when the connection is restored:

Persist Paused Mutations

Paused mutations can be persisted and resumed later:

React Native Configuration

Configure network detection for React Native:

Testing Network Modes

Test offline behavior in your app:

Focus Manager

TanStack Query also includes a Focus Manager for window focus detection:

Refetch on Reconnect

Control refetching when coming back online:

Best Practices

1

Choose the Right Mode

  • Use 'online' for server data (default)
  • Use 'always' for local-first apps
  • Use 'offlineFirst' for progressive web apps
2

Handle Paused State

Always check fetchStatus to show appropriate loading states:
3

Persist Mutations

Use persistence for critical mutations that should survive offline periods.
4

Custom Detection

Implement custom online detection for more reliable connectivity checks.
5

Test Offline Scenarios

Always test your app’s behavior in offline mode.

Common Patterns