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

145
Views
order of execution in useEffect clean up
  useEffect(() => {
    return history.replace({
      pathname: "path/A",
    });
  }, []);

  useEffect(() => {
    return history.replace({
      pathname: "path/B",
    });
  }, []);

When the component unmounts, what will be the URL? What determines the order of execution of the above 2 useEffect?

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

0

Due to the nature of you passing no deps; both of these useEffects will only be rendered on component mount. Therefore, the result is (and always will be) "path/B".

If you wanted it to change on component unmount, you'd need to add a return function to one of them.

useEffect(() => {
    history.replace({ pathname: "path/B" });
    return () => history.replace({ pathname: "path/B" });
}, []);
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!