Teyro
CoursesFor creatorsBlog
Log inGet started
Tey Mascot
LOADING.

Every expert you admire was once a beginner who refused to quit.

Teyro

The fun way to finish learning coding and AI: short daily lessons with streaks, leagues and friends.

Get the app

Learn

  • All courses
  • Learn coding
  • Learn AI
  • Learn online
  • How it works
  • Leagues
  • Get the app

Creators

  • Teach on Teyro
  • How teaching works
  • Teach coding online
  • Teach AI online
  • Join as a Founding Creator
  • Creator log in

Resources

  • Blog
  • Features
  • Use cases
  • Compare
  • FAQ

Legal

  • Terms of Use
  • Privacy Policy

© 2026 Teyro · support@teyro.app

HomeBlogSkill Building & Careers
Skill Building & Careers

Fetching Data in React Native: fetch, Loading States and Errors

Learn how to call an API from React Native with fetch, show loading and error states, handle empty results and avoid common network problems on devices.

The Teyro TeamOct 26, 20261 min read
On this page5 sections
  1. Direct answer
  2. Example
  3. Where Teyro fits
  4. The bottom line
  5. More guides

Real apps get data from servers. Real apps also handle slow and failing networks.

Direct answer

Use fetch in a useEffect, store the result in state and keep separate states for loading and errors. On a device, never use localhost for your own server. Use your computer's network address or a deployed URL.

Example

import { useEffect, useState } from "react";
import { ActivityIndicator, FlatList, Text, View } from "react-native";

export default function Posts() {
  const [posts, setPosts] = useState([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState(null);

  useEffect(() => {
    (async () => {
      try {
        const res = await fetch("https://jsonplaceholder.typicode.com/posts");
        if (!res.ok) throw new Error("HTTP " + res.status);
        setPosts(await res.json());
      } catch (e) {
        setError(e.message);
      } finally {
        setLoading(false);
      }
    })();
  }, []);

  if (loading) return <ActivityIndicator />;
  if (error) return <Text>Something went wrong: {error}</Text>;
  if (posts.length === 0) return <Text>No posts yet</Text>;

  return (
    <FlatList
      data={posts}
      keyExtractor={(p) => String(p.id)}
      renderItem={({ item }) => <Text style={{ padding: 12 }}>{item.title}</Text>}
    />
  );
}

Where Teyro fits

Teyro's React Native for Beginners course turns this into short lessons you can play in a few minutes a day. It has 80 lessons, and you can start free.

The bottom line

Loading, error, empty and success: handle all four states.

More guides

  • Props vs State in React Native
  • React Native Animations
  • React Native Simulator Setup
  • Useeffect in react native
  • React Native for Beginners course

Frequently asked questions

How do I call an API in React Native?

Use the built-in fetch function, usually inside useEffect, and store the result in state.

Why does my API work in the browser but not on my phone?

You may be using localhost, which refers to the phone itself. Use your computer's local network address or a deployed URL.

How do I show loading and error states?

Keep separate state for loading and error, and render different UI for each.

Learn it by playing

React Native for Beginners turns this into short, playable lessons. Free to start.

See the React Native for Beginners course

Free to start · No credit card needed

Share

Written by

The Teyro Team

Learning Team at Teyro

We build Teyro — an AI-powered learning platform that turns skill-building into a daily habit through bite-sized, gamified lessons. We write about the learning science and study strategies that shape our product.

More from The Teyro Team

On this page

  • Direct answer
  • Example
  • Where Teyro fits
  • The bottom line
  • More guides

Keep reading

Skill Building & Careers

Best Careers for 2027: High-Demand Jobs and the Skills to Get Them

The best careers for 2027 and the jobs most in demand, based on BLS and World Economic Forum data, plus the skills each path needs.

Oct 30, 20263 min read
Skill Building & Careers

Best Certifications for 2027: Tech, Data, Cloud and Business

The best certifications for 2027 in cloud, security, data, project management and AI, who each one suits, and when a portfolio matters more.

Oct 30, 20263 min read
Skill Building & Careers

Best Programming Language to Learn in 2027 (for Your Goal)

The best programming language to learn in 2027 depends on what you want to build. Compare Python, JavaScript, TypeScript, SQL and C.

Oct 30, 20263 min read