Capítulo 14 de 80
networkMode controls how a query/mutation behaves without a network connection: 'online' (default) pauses instead of failing, 'always' ignores connectivity entirely, and 'offlineFirst' tries once (letting a service worker/HTTP cache answer) then behaves like 'online' on a real miss.
online (default): fetches only pause (fetchStatus: 'paused') when offline rather than erroring; retries also pause and resume on reconnect (a "continue," not a "refetch" — independent of refetchOnReconnect, and skipped if the query was cancelled meanwhile).always: ignores connectivity completely — appropriate when the queryFn doesn't need a real network connection at all (reading AsyncStorage, a Promise.resolve stub). Retries don't pause either; failures go straight to error. refetchOnReconnect defaults to false here since "back online" isn't a meaningful signal for data that never depended on the network.offlineFirst: middle ground for offline-first PWAs or HTTP Cache-Control-backed requests — the first attempt runs (may be answered from cache/service worker), and only a genuine cache-miss failure falls back to online-style paused retries.OnlineManager's state without touching real network connectivity — useful for testing without disconnecting Wi-Fi.networkMode option.networkMode | Fetch when offline | Retries when offline | refetchOnReconnect default | Use for |
|---|---|---|---|---|
online (default) | Paused | Paused | true | Normal server-data fetching |
always | Runs regardless | Never pauses, goes to error | false | Local/AsyncStorage/non-network sources |
offlineFirst | Runs once (may hit cache/SW) | Paused after a real miss | true | Offline-first PWAs, HTTP-cache-backed requests |
online for anything actually hitting a server — it's the mode that treats "no connection" as a pause, not a failure, and resumes cleanly on reconnect.always for queries whose queryFn never touches the network — otherwise they'll incorrectly sit paused while offline for no reason.isPending alone can mislead you about loading state: a first-mount query with no connection is pending + paused, not pending + fetching — check fetchStatus/isPaused if the distinction matters to your UI.fetchStatus field this chapter's pause/fetching/idle states extend.