React Native · Mobile UI at native speed

How do you handle networking and API calls?

MediumnetworkingfetcherrorsUpdated Oct 2026
Quiz this track

Short answer

Use fetch or a client such as axios, add timeouts and cancellation with AbortController, handle non-2xx responses explicitly, and put retries and caching in a data layer rather than in each screen.

React Native provides fetch and XMLHttpRequest, both backed by native networking. fetch does not reject on HTTP error statuses, so a 500 response still resolves. A robust client checks response.ok and parses errors deliberately.

ts
export async function getJson<T>(url: string, signal?: AbortSignal): Promise<T> {
  const controller = new AbortController();
  const timeout = setTimeout(() => controller.abort(), 10000);
  const combined = signal ?? controller.signal;

  try {
    const response = await fetch(url, {
      headers: { Accept: "application/json" },
      signal: combined,
    });

    if (!response.ok) {
      throw new Error("Request failed with status " + response.status);
    }

    return (await response.json()) as T;
  } finally {
    clearTimeout(timeout);
  }
}
A timeout and an explicit status check prevent hanging screens and silent failures.

What belongs in the data layer

  • Base URL and auth header injection in one place
  • Timeout, cancellation and retry policy with exponential backoff
  • Response validation at the boundary
  • Cache policy and invalidation through a query library
  • Error normalisation so the UI can distinguish offline from server errors

On mobile, connectivity is intermittent. A request may fail because the radio is asleep, the user moved between networks, or the app was backgrounded. Treat failure as normal, show a retry affordance, and cancel in-flight requests when a screen unmounts to avoid state updates after navigation.

Do not retry non-idempotent requests automatically unless the server supports idempotency keys. Retrying a payment or order creation can duplicate the action.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1Does fetch reject on a 404 or 500 response?
  2. 2How do you cancel a request when a screen unmounts?
  3. 3When is it safe to retry a request?
  4. 4How do you handle authentication refresh?

Say it in the interview

I centralise networking in a small client that injects headers, applies a timeout, checks response.ok and normalises errors. I pass an AbortSignal so requests cancel when a screen unmounts, and I only retry idempotent calls with backoff. Caching and invalidation live in the data layer, which keeps screens focused on rendering states rather than request mechanics.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live React Native mock interview and get scored feedback on depth, clarity and confidence.