State Management
We use a hybrid approach to state management.
1. Server State (React Query)
90% of the data in the app comes from the API (Horses, Alerts, Cameras). We use TanStack Query to handle:
- Caching (Instant validity).
- Background Refetching.
- Optimistic Updates (UI updates before server confirms).
const { data: horses } = useQuery({
queryKey: ["horses", stableId],
queryFn: () => api.getHorses(stableId),
});
2. App State (React Context)
For global application state, we use Context Providers.
- AuthProvider: Stores the JWT token in
SecureStore(biometric-ready) and exposessignIn/signOut. - SocketProvider: Maintains the
Socket.ioconnection singleton.
3. Navigation State
Handled implicitly by Expo Router based on the file system (app/(tabs)/index.tsx).