Menu

TanStack Query did my offline mode, my retries and my cache. I wrote the rules.
πŸ“°

TanStack Query did my offline mode, my retries and my cache. I wrote the rules.

DEV Community: reactΒ·Onkar DeokateΒ·9 days ago
#u3xGEpMF
#devtoreact#devto#dev#query#tanstack
Reading 0:00
15s threshold

ParkEase has two React apps talking to the same API: an Android app (Expo, React Native) for drivers, owners, valets and car washers, and an admin panel (React and Vite). Both get every byte of server data through TanStack Query . Neither has Redux, Zustand or a hand-rolled fetch-into- useState anywhere.

That was a rule, not a preference. Here's why it was the right one, and how differently the two apps use the same library.

The rule: server state is not app state

The mobile rules say it in one line: TanStack Query for server state, never Redux, never Zustand. A booking, a list of parking spots, an earnings summary: these belong to the server. The app holds a cached copy , and the question is only how fresh that copy is and what to do when it's wrong.

Putting that copy in a global store means rebuilding caching, deduping, retries, refetching and invalidation yourself, badly. Leaving it in TanStack Query means one rule: read it straight from the cache, never copy it into useState .…

Continue reading β€” create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.