Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

252
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda