Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

215
Views
Failing to fetch data from json using fetch in react native

So I am using a fake backend called json server and I am trying to fetch data from it but it is throwing this error

[Unhandled promise rejection: TypeError: Network request failed]

This is what my code looks like starting with the json server file

{
    "listings": [
      { 
        "id": 0,
        "image": "../app/assets/jacket.jpg",
        "title": "Red jacket for sale",
        "subtitle": "$400"
      },
      { 
        "id": 1,
        "image": "../app/assets/couch.jpg",
        "title": "Nice couch for basking in",
        "subtitle": "$100"
      },
      { 
        "id": 2,
        "image": "../app/assets/image.jpg",
        "title": "Just an image for sale nje",
        "subtitle": "$10"
      }
    ]
  }

And then my logic file where i call using fetch

import React, {useEffect, useState} from 'react'
import { StyleSheet, Text, View } from 'react-native'

export default function ItemsScreen() {
    const [listings, setlistings] = useState(null);

    useEffect(() => {
        fetch("http://localhost:8000/listings")
            .then(res => {
                return res.json();
            })
            .then(data => {
                setlistings(data)
            })
    }, []);

    return (
        <View>
            {listings && listings.map(listing => (
                <View key={listing.id}>
                    <Text>{listing.title}</Text>
                    <Text>{listing.subtitle}</Text>
                </View>
            ))}
        </View>
    )
}

const styles = StyleSheet.create({})

And finally my App.js file

import React, {useState} from 'react'
import { Button, StyleSheet, Text, View } from 'react-native'

import ItemsScreen from './app/screens/ItemsScreen'

export default function App() {

  return (
        <ItemsScreen />
  )
}

const styles = StyleSheet.create({})

This is all of it. Where could I be going wrong?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!