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

98
Views
Why is useEffect causing my application to rerender

I have a useEffect function that is calling some data from a database and then sets the value under as 'data'. My problem is that useEffect is causing my application to render twice causing the user profile to give two values during the session, making me unable to use data:

enter image description here


const [data, setData] = useState([]);
const [error, setError] = useState(null);

useEffect(() => {
    fetch("http://localhost:5000/record")
      .then((res) => res.json())
      .then(
        (result) => {
          setData(result);
        },
        (error) => {
          setError(error);
        }
      );
  }, []);
  let userProfile = data.find((x) => (x.email = user.email));
  console.log(userProfile);
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I think this behavior is expected.

You can use useLayoutEffect if you want to have more control over when to fetch the data.

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!