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

500
Views
Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only 1 present

In my React app, I have the following useEffect and cleanup.

useEffect(() => {
    if (pageLoad) {     
        window.addEventListener('beforeunload', (e) => {
            localStorage.removeItem(SOME_KEY);
        });
        return () => {
            window.removeEventListener('beforeunload');
        }
    }
}, [pageLoad]);

However, I get the following error. Is there some issue with the removeEventListener ?

Failed to execute 'removeEventListener' on 'EventTarget': 2 arguments required, but only 1 present
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can pass same function to removeEventListener

useEffect(() => {
  if (pageLoad) {
    const cb = (e) => {
      localStorage.removeItem(SOME_KEY);
    };
    window.addEventListener("beforeunload", cb);
    return () => {
      window.removeEventListener("beforeunload", cb);
    };
  }
}, [pageLoad]);
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!