Course contents
Connecting to a REST API
Fetch server data with TanStack Query: caching, pull-to-refresh, refetching on foreground and reconnect, and honest loading, empty and error states.
fetch works fine in React Native. The hard part is everything around it: not refetching on every visit, retrying when the network blips, refreshing when the user comes back to the app, and showing something sensible while loading or after a failure. TanStack Query (v5, version 5.107 as of November 2026) handles most of that, but on mobile you have to connect two of its triggers yourself.
Fresh, stale and garbage-collected
TanStack Query keeps a cache keyed by queryKey. Two timers control it. staleTime is how long data counts as fresh: within that window, visiting the screen again reads the cache with no request. gcTime (called cacheTime before v5) is how long unused data stays in memory before it's dropped. On a phone, a staleTime of 30 to 60 seconds for lists like Tipjar's history saves a request on almost every back-and-forth navigation, which is battery and data the user doesn't spend.
History uses staleTime: 60_000. The user opens History, goes to Settings, and comes back 20 seconds later. What happens?
Two mobile triggers to wire up
On the web, TanStack Query refetches stale data when the browser tab regains focus and when the browser comes back online. React Native has no browser events, so you connect them: point focusManager at React Native's AppState, so returning to the app counts as focus, and point onlineManager at a network status library such as @react-native-community/netinfo. Then pull-to-refresh covers the case where the user explicitly asks for new data.
Codex wrote this from an older tutorial. Click the lines that won't work, or won't work on a phone.
Design all the states
Every screen that loads data has at least four states: loading for the first time, showing data, empty, and failed. Offline adds a fifth, showing cached data with a note that it may be out of date. Agents tend to build the happy path and a spinner. Name the others in your prompt, and say what the error state should offer, usually a Retry button and a short human message rather than the raw error. Expo's expo-data-fetching skill covers these states, so with the Expo plugin installed, Codex has guidance to follow.
The transcript is canned — no real API calls. The point is to internalize the loop: user → plan → tool → result → answer.
cacheTime option?