Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To make a React app work offline, combine separate pieces: TanStack Query manages server-state caching and network behavior, IndexedDB can retain structured data across reloads, and a service worker can cache app assets or selected request responses. Persisting a query cache helps users read previously fetched data; it does not, by itself, make edits durable or synchronize them with a server.

Decide what “offline” needs to mean

Offline support can mean several different things. Decide which outcomes your app promises before choosing storage or network settings:

  • Read previously fetched data: show server data that was cached in memory or restored from persistent storage.
  • Keep user changes while disconnected: save drafts or other local intent durably, rather than relying on a query result as the editable record.
  • Reconcile changes with the server: queue and replay writes, then handle validation, duplicates, authentication, ordering, and conflicts.

These are related but distinct capabilities. A persisted TanStack Query cache primarily supports the first. Durable offline editing needs an explicit local write model; synchronization needs a defined contract between that model and the server.

Choose a TanStack Query network mode for each workload

Current TanStack Query documentation describes three network modes. They control how queries and mutations behave in relation to the library’s online state; none of them stores data durably.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
Mode When it fits Behavior to account for
online (default) Work that needs a network, such as a normal API query. Queries and mutations pause when TanStack Query considers the app offline. A query can be pending while its fetch status is paused, so inspect fetch status as well as query status when deciding what the UI should show.
always A query function that reads local data and does not need a network. It ignores online state. Use it only when running the function while disconnected is useful and safe.
offlineFirst A request that may be fulfilled locally first, for example through a service worker or HTTP cache. The query function runs once; after a failure, retries pause while offline. This can allow a cache-backed first request without treating every retry as immediately available.

Set modes at the query or mutation level when workloads differ rather than treating one global setting as an offline architecture. Reconnect behavior is useful only if the underlying function can reach the right source and the app knows how to refresh or reconcile its data. A browser’s navigator.onLine signal should not be treated as proof that a particular server is reachable; use TanStack Query’s online-state abstraction, and consult the current OnlineManager reference if the app needs custom events.

Persist and restore the query cache deliberately

TanStack Query’s persistence integration stores dehydrated query and mutation state, restores that state later, and subscribes to cache changes so subsequent changes can be saved. It is a way to retain Query state, not a domain database or synchronization protocol.

Keep in-memory garbage collection aligned with persistence

Set the QueryClient’s gcTime to at least the persistence maxAge when the goal is to keep restored cache entries available for that full period. The current persistence guide notes that hydration’s default gcTime is five minutes while persistence maxAge defaults to 24 hours. Without an appropriate gcTime, restored data can be garbage-collected from memory sooner than the persisted age suggests. These are configuration defaults, not a guarantee that the browser will retain the backing storage.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.

Make startup order explicit

  1. Create one stable QueryClient. Keep it stable across renders so restoration and cache subscriptions operate on the same client.
  2. Start restoration before dependent work. Use the persistence provider or an explicit restore flow, and show an intentional loading or restoration state where needed.
  3. Decide how restored data and refetches interact. Avoid allowing eager queries to race an incomplete restore unless the app has deliberately chosen which result should win.
  4. Version persisted state when necessary. Use a cache buster or build identifier if a deployment makes older stored state incompatible. Expired, busted, erroneous, or empty persisted state is removed by the persistence flow.

The official offline integration example illustrates waiting for restoration before some router fetches and resuming paused mutations afterward. That example is hosted in the v4 documentation; check current v5 documentation for version-sensitive API names and defaults before adopting its code.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose between persisting Query state and storing domain records

TanStack Query’s persistence abstraction is storage-agnostic. An IndexedDB-backed persister can save dehydrated QueryClient state, or the app can keep domain records in IndexedDB and have query functions read from that local source. These choices solve different problems.

Approach Best suited to What the app still owns
Persist the Query cache Restoring previously fetched Query state after a reload, with limited additional storage modeling. Cache age and compatibility, restoration order, and any separate design for offline edits and server reconciliation.
Store domain data in IndexedDB Structured records, indexed lookups, durable local edits, and a deliberate local data model. Schema migrations, relationships and transactions, the Query functions that read local data, and synchronization and conflict rules.

The core Query library does not create an IndexedDB schema for the app. If users must edit data offline, make the local records and queued intent explicit rather than assuming a persisted server-state cache is the source of truth for every workflow.

Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.

Use IndexedDB for structured local data

IndexedDB is an asynchronous browser database for structured records. It supports versioned schemas, transactions, and indexes, making it a better fit than string-only Web Storage for many larger or more structured data models.

  1. Open the database at a known version. Handle the upgrade event to create or update object stores when the schema version changes.
  2. Choose stores around the records the app owns. Define the shape and identifiers for local entities and, where needed, queued changes.
  3. Use a transaction for related operations. Start a transaction on the relevant store or stores, issue reads or writes, and handle request errors and transaction completion.
  4. Add indexes for frequent lookups. Index fields used to find records efficiently instead of repeatedly scanning an entire store.
  5. Make migrations and failure states part of the design. Schema upgrades can affect existing local data, so test how the app handles upgrade errors and incompatible records.

For a local-only query, use a query function that reads the appropriate IndexedDB records and select a network mode that does not pause that local read while offline. For a server-backed query, decide separately whether to read restored cached state, request a response that might be served by a service worker, or wait for connectivity.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add a service worker for assets and request-response caching

A service worker can intercept requests and serve cached app assets or selected responses when a network is unavailable. Its install event can populate a cache. It complements IndexedDB and TanStack Query: it does not automatically persist arbitrary API data as domain records or resolve conflicting edits.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft
Layer Natural role Lifecycle concern
Service worker and Cache API App assets and request-response caching. Choose safe request rules, decide how stale responses are refreshed, and retire old cache versions. During updates, old and new worker versions may coexist until activation.
IndexedDB Structured records, transactions, indexes, and local data models. Manage database versions, schema upgrades, and the retention of locally owned data.

Service workers require a secure context: generally HTTPS, with localhost treated as secure for development. Pairing a service worker with offlineFirst can make sense when the initial fetch may be fulfilled from a local request cache; still define which requests may be cached and what happens when a cached response is stale.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Design offline writes as a synchronization feature

TanStack Query can restore paused mutations and resume them, but a mutation saved before reload needs a mutation function available again afterward. The official example sets a default mutation function, waits for persistence restoration to succeed, then resumes paused mutations and invalidates queries. That mechanism does not choose a safe sync policy for a particular product.

Before promising that offline edits will “sync,” specify the behavior for each of these cases:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.
  • Durable intent: save the user’s intended change locally before reporting it as safely queued.
  • Visible state: distinguish saved locally, queued, syncing, synced, and failed states so users can understand what has happened.
  • Retries and duplicate protection: decide what is retried and use idempotency keys or an equivalent server-supported mechanism to avoid applying a repeated request twice.
  • Authentication and authorization: define what happens when credentials expire while a change is queued, and revalidate permissions on the server when sending it.
  • Validation and ordering: handle server rejection and determine whether dependent changes must be sent in a particular order.
  • Conflicts: define whether the server, latest edit, or user decides the result when local and remote records diverge. Consequential or collaborative records need an explicit server contract and conflict policy.

Do not resume queued work until restoration has completed and the app has a valid execution path for the mutation. Resuming after reload is a delivery mechanism; application-specific retry, authentication, and conflict decisions remain necessary.

Account for browser retention and privacy

Browser storage is best-effort by default. Quotas and eviction policies vary, users can clear stored data, and private browsing may impose different limits or remove data when the session ends. Treat locally stored data as useful persistence, not permanent storage.

An app can call navigator.storage.persist() to request stronger retention. A browser may prompt, approve automatically, or deny the request according to its policy, so the app must still handle data being unavailable.

Do not store secrets or sensitive records without a deliberate threat model and retention plan. Include cleanup for logout and tenant changes, and use cache versioning when old state is incompatible. Local cleanup helps prevent data from crossing account boundaries on a shared browser, but it does not replace server-side authorization.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Plan the layers together, but test their failure boundaries

For a read-only offline experience, a persisted cache may be enough if the UI communicates that it is showing previously fetched data and can recover when storage is missing. If the app also needs an offline shell or cached responses, add a service worker with deliberate cache rules. If users can create or edit records offline, model those records and queued changes in durable storage, then specify how they are validated and reconciled when connectivity returns.

Test more than the happy path: first launch without a connection, reload after a local change, expired or incompatible persisted cache, browser-cleared storage, failed database upgrades, an expired login, duplicate delivery, and a server-side conflict. The expected result for each case should follow from the product’s offline promise—not from assuming that a cache, network mode, or service worker solves it automatically.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.