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

143
Views
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 answers
Answer question

0

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

fetch method is calling itself, try to change method name

about 4 years ago · Juan Pablo Isaza Report
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!