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

275
Visualizações
Window.innerWidth gives wrong width value in react

I have no idea why I am getting the wrong value for window.innerWidth. Below is my code and the code after the isMobile check is important to run.

import CmsBlock from '@magento/venia-ui/lib/components/CmsBlock';
import { useWindowSize } from '@magento/peregrine/lib/hooks/useWindowSize';

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

    const handleTabClick = useCallback((element) => {
        element.classList.toggle('active-tab');
    }, []);

    useEffect(() => {
        if (handlers.current) {
            for (const {element, handler} of handlers.current) {
                element.removeEventListener("click", handler);
            }
            handlers.current = null;
        }

        const buttonElements = document.querySelectorAll('.col-links');
        console.log(isMobile, window.innerWidth)
        if (isMobile) {
            handlers.current = [];
            for (const element of buttonElements) {
                const handler = handleTabClick.bind(null, element);
                handlers.current.push({ element, handler });
                element.addEventListener("click", handler);
            }
        } else {
            for (const element of buttonElements) {
                element.classList.remove('active-tab');
            }
        }

    }, [isMobile, footer, handleTabClick]);
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