Networking Best Practices
A condensed summary of the 25 most important networking practices drawn from every page in this section.
Search across all documentation pages
A condensed summary of the 25 most important networking practices drawn from every page in this section.
Centralize HTTP in one client module: Attach base URL, auth headers, timeouts, and HTTPS checks in api/client.ts - features never scatter raw fetch to arbitrary hosts.
Enforce HTTPS in production builds: Reject http:// at the client choke point - android.usesCleartextTraffic is for local dev only.
Always set request timeouts: Use AbortController + timer (8–15 s reads, tighter for mutations) - LTE handoffs hang indefinitely without them.
Cancel in-flight requests on unmount: Pass signal from useEffect cleanup or TanStack Query queryFn - prevents setState-after-unmount and wasted radio time.
Parse JSON at the network edge with Zod: Never cast res.json() blindly - one schema per endpoint catches backend drift before users see crashes.
Classify errors before showing copy: Offline (TypeError), timeout (AbortError), HTTP status, and parse failures need different messages - see Network Failure UX.
Default to fetch on Hermes: Zero extra bundle bytes - add axios only when interceptors, isAxiosError, or team conventions justify ~13–15 KB gzip.
Implement interceptors once: Whether fetch wrapper or axios, auth attachment and 401 handling live in a single module paired with Refresh Token Rotation.
Upload progress requires XMLHttpRequest or FileSystem: Neither fetch nor axios exposes reliable upload progress on React Native - plan XHR or expo-file-system for avatars and media.
Adopt TanStack Query for shared server state: Replace manual useEffect fetch hooks when multiple screens read the same API - cache, dedupe, and background refetch are free.
Wire focusManager to AppState: Refetch stale queries when the app becomes active - mobile has no window focus events.
Wire onlineManager to NetInfo: Pause query retries offline; resume on reconnect - uncapped retries in airplane mode drain battery.
Tune staleTime per query key: 30–60 s for feeds, longer for catalogs - global staleTime: 0 refetches too aggressively on every foreground.
Show staleness labels: Display dataUpdatedAt or "Updated 2 min ago" - users on flaky LTE need to know data may be old.
Retry GET with exponential backoff and jitter: Cap at 3–4 attempts - jitter prevents synchronized client spikes when towers recover.
Never retry non-idempotent POST blindly: Use Idempotency-Key headers and server deduplication for payments and creates - see Retries, Backoff & Idempotency.
Set TanStack Query mutations.retry to 0 by default: Transport-layer retry with stable idempotency keys beats duplicate mutation function invocations.
Persist read caches selectively: persistQueryClient with AsyncStorage or MMKV for catalogs - clear on logout; exclude unencrypted PII.
Close WebSockets in background: Reconnect with backoff on foreground - leaving sockets open wastes battery and gets killed by the OS.
Offer polling fallback for real-time features: Slower intervals on cellular and in background - or push notifications for must-deliver events.
Choose urql for lean GraphQL; Apollo for complex graphs: Measure bundle with expo export - persist normalized cache with size caps on device.
Default to system TLS; pin only with an ADR: Certificate pinning needs native rebuilds, rotation runbooks, and breaks corporate proxies - most apps should not pin on day one.
Queue offline mutations with optimistic UI: Persist failed writes, show pending state, flush on reconnect - pair with Optimistic UI.
Never block the UI thread on network parsing: Large JSON transforms belong off the hot path; stream or paginate huge lists - keep presses responsive.
Pre-release networking checklist: Physical device on LTE, airplane-mode retry behavior, logout cache clear, idempotency spot-check, and TLS policy grep before store submission.
fetch with a thin client wrapper unless interceptors or upload ergonomics force axios. TanStack Query sits above either transport.
QueryClientProvider, focusManager + AppState, onlineManager + NetInfo, sensible staleTime, and signal in queryFn.
Rare - regulated finance/health with security ops owning rotation. Default system TLS per Certificate Pinning and Security Rules.
Networking pages cover transport, cache, and failure UX. Full offline-first adds SQLite sync - Offline-First Basics.
Stack versions: This page was written for React 19.2.3, React Native 0.86.0, and Expo SDK 57 (
expo~57.0.4).
Reviewed by Chris St. John·Last updated Jul 19, 2026