Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
React Native : multiple renders at fetching data with useEffect hook

I'm having two problems my code. The first is that data is undefined, i'm not fetching data from the API. The seccond is that the hook useEffect it's not working as it should, like componendidmount, and it's on a loop re rendering the coponent. this is my code :

import { StatusBar } from 'expo-status-bar';
import React ,{useState,useEffect} from 'react';
import { StyleSheet, Text, View } from 'react-native';



export default function App() {

  const [loading, setLoading] = useState(true);
  const [users, setUsers] = useState([]);

  const fetch = async () =>{
    try{
      let data = await fetch("https://api.sampleapis.com/coffee/hot", {method: 'GET'});
      let json = await data.json();
      setUsers(json);
      setLoading(false);
    }
    catch(err){
      console.log("Im catching the error");
      console.log(err);
      setUsers([]);
      setLoading(false);
    }


  }

  useEffect(() => {
   fetch();
  },[])



  return (
    <View style={styles.container}>
      {loading?<><Text>Loading...</Text></>:<Text>Data fetched</Text>}
    </View>
  );
}
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

....    
const fetch = async () =>{
....

fetch method is calling itself, try to change method name

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda