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

246
Views
Click listener firing multiple times in react

I am working on a magento 2 PWA studio project and a click listener seems to be firing multiple times. I have two languages in website. On the first one, the click listener fires fine. When i switch to the second language, it fires multiple times. Below is the code.

import CmsBlock from '@magento/venia-ui/lib/components/CmsBlock';

const isMobile = useWindowSize().innerWidth < 1024;
const footer = <CmsBlock identifiers="footer" />;

const handleTabClick = useCallback((element) => {
        console.log('handleTabClick')
        element.classList.contains('active-tab') ? element.classList.remove('active-tab') : element.classList.add('active-tab');
    });

useEffect(() => {        
     const buttonElements = document.querySelectorAll('.col-links');
     if (isMobile) {
         buttonElements.forEach(element => {
              element.addEventListener('click', handleTabClick.bind(null, element));
         })
     } else {
         buttonElements.forEach(element => {
              element.classList.contains('active-tab') && element.classList.remove('active-tab');
            })
        }
}, [isMobile, footer, handleTabClick]);

If i return from useEffect and remove the event listener at component un render time,the click listener does not seem to be fired at all when i switch the language. What is wrong with my code?

Note: When language switch happens, the entire website is refreshed.

about 4 years ago · Juan Pablo Isaza
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!