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

180
Views
useEffect is not working in parent Component if child component is added in react

I want to pass data to child component after getting data from API, if I remove the child component its working

const parentComponent= (props) => {
  const [loans, setLoans] = useState({});

  useEffect(() => {
    axios.get(`api`).then((result) =>{ 
      let { data } = result;
      console.log('result', result)      
      setLoan(data);  
    });
  }, []);

 return(
  <ChildComponent data={loans} />
)
}

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You are not setting the to the state loans. You have to use setLoans instead of setLoan. Check this, it should work now.

const parentComponent= (props) => {
  const [loans, setLoans] = useState({});

  useEffect(() => {
    axios.get(`api`).then((result) =>{ 
      let { data } = result;
      console.log('result', result)      
      setLoans(data);  
    });
  }, []);

 return(
  <ChildComponent data={loans} />
)
}
about 4 years ago · Juan Pablo Isaza Report

0

const [loans, setLoans] = useState({}); use setLoan or changed name after console.log. You have done setLoans which is not equal to setLoan

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!