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

149
Views
windows.location.reload() only one time in reactJS

Hi all I have following code:

     const [firstRender, setFirstRender] = useState(true);

      const refreshPage = () => {
         window.location.reload();
      };

       useEffect(() => {
        if (firstRender) {
          refreshPage();
         setFirstRender(false);
        }
       }, [firstRender]);

What I am trying to do is when the user enter page useEffect should trigger and reload page.

So every time when user enter the page first it should reload and then user can do what he/she want.

But after refreshing firstRender is always becoming true and I getting infinity refreshing call.

So please me to resolve this problem.

about 4 years ago · Santiago Trujillo
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!