Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

217
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda