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

144
Visualizações
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 Respostas
Responde à pergunta

0

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

fetch method is calling itself, try to change method name

about 4 years ago · Juan Pablo Isaza Relatório
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