Axios configuration, custom hooks, and request patterns
All HTTP communication flows through a single Axios instance defined in src/services/api-config/axios.js. On top of that, a set of TanStack Query–based custom hooks provides a consistent interface for every type of request.
Before every request, the interceptor reads the token key from AsyncStorage and attaches it as a Bearer token. The Accept: application/json header is also set unconditionally.
The response interceptor watches for 401 Unauthenticated. responses. When detected, it clears the stored token so the next app launch returns to the login screen.
The response interceptor does not currently navigate the user to the login screen automatically after clearing the token. The next app launch (or any navigation action that checks loggedIn) will redirect to the unauthenticated stack.
All hooks live in src/services/api-hooks/. They accept an endpoint string (the path relative to baseURL) and an optional config object that is spread into the underlying TanStack Query options.
src/services/api-hooks/useUploadImage.jsUploads a single image as multipart/form-data. The image object must have uri, type, and optionally name / fileName fields (as returned by react-native-image-picker).
src/services/api-hooks/useUploadFiles.jsUploads multiple files in a single multipart/form-data request. The files argument is an object whose keys become the FormData field names.
src/services/api-hooks/useOnScrollMethod.jsWraps useInfiniteQuery for paginated lists. Pages are fetched by appending ?page=N to the endpoint. Pagination stops when current_page === last_page in the response.
Errors from mutations and queries surface in two ways:
Toast messages
react-native-toast-message is used to display one-line error descriptions. Call Toast.show inside an onError callback with the API error message from error.response?.data?.message.
Inline error states
Query hooks return isError and error fields. Components read these to render inline error text or retry buttons.
The app uses @react-native-community/netinfo to detect connectivity changes. When the device is offline, requests will fail with a network error rather than an API error.
import NetInfo from '@react-native-community/netinfo';// Subscribe to connectivity changesconst unsubscribe = NetInfo.addEventListener(state => { if (!state.isConnected) { Toast.show({ type: 'error', text1: 'No internet connection' }); }});// One-time checkconst state = await NetInfo.fetch();console.log('Connected:', state.isConnected);
TanStack Query will automatically retry failed requests up to 3 times by default. For operations where an offline state should fail immediately, set retry: false in the config passed to the hook.