Lesson 8 of 11
Offline-First Architecture & App Signing
Offline-first makes the app work without internet as the default, not as an afterthought. App signing ensures your binary is trusted by the OS and cannot be tampered with after build.
Offline-First Strategy
- **Read from cache first, then network**: TanStack Query's `staleTime` keeps data in memory or `gcTime` keeps it on disk; users see data immediately, even offline
- **Optimistic mutations**: Write changes locally first (TanStack Query optimistic updates or Zustand), sync to server when connected. TanStack Query's `networkMode: 'offlineFirst'` retries mutations automatically
- **Persistent cache**: Configure TanStack Query's `PersistQueryClient` with MMKV to persist the query cache to disk - survives app restarts
- **Queue for mutation retries**: Use Zustand's persist middleware to queue writes that failed due to offline state, and replay them when `onlineManager` reports connectivity restored
- **User feedback**: Show an offline banner (Module 5's `useNetworkStatus`), disable actions that strictly require server (payment, real-time), show cached timestamps
- **Conflict resolution**: Last-write-wins is simplest. Timestamp your mutations server-side; if the server has a newer version, reject the mutation with a conflict error and ask the user to refresh
App Signing - EAS Credentials
# EAS manages credentials automatically
eas credentials
# ---- iOS signing ----
# Apple Developer account required ($99/year)
# EAS registers the bundle identifier (com.yourcompany.app)
# EAS generates the Distribution Certificate and Provisioning Profile
# EAS uploads them to Apple and stores them securely on Expo servers
# ---- Android signing ----
# EAS generates the upload keystore (.jks file)
# Play Store uses the upload key to verify your submission
# Play App Signing: Google holds the release key (final key installed on devices)
# You can't push an update signed with a different key - guard your keystore!
# ---- Backup credentials ----
# Download and store in a secure password manager:
eas credentials --platform android --profile production --json > android-credentials.json
eas credentials --platform ios --profile production --json > ios-credentials.json
# ---- Rotate credentials if compromised ----
# Android upload key rotation: contact Google Play support
# iOS certificate: revoke in developer.apple.com, eas credentials will regenerateTip
Tip
Practice OfflineFirst Architecture App Signing in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
Generating Android upload keystores and Apple distribution provisioning profiles
Practice Task
Note
Practice Task - (1) Write a working example of OfflineFirst Architecture App Signing from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with OfflineFirst Architecture App Signing is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready react native code.
Key Takeaways
- Offline-first makes the app work without internet as the default, not as an afterthought.
- *Read from cache first, then network**: TanStack Query's `staleTime` keeps data in memory or `gcTime` keeps it on disk; users see data immediately, even offline
- *Optimistic mutations**: Write changes locally first (TanStack Query optimistic updates or Zustand), sync to server when connected. TanStack Query's `networkMode: 'offlineFirst'` retries mutations automatically
- *Persistent cache**: Configure TanStack Query's `PersistQueryClient` with MMKV to persist the query cache to disk - survives app restarts
Finished this lesson?