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

180
Visualizações
Event handler does not work properly in react

I have this code in HomePage component and when pressing arrow down/up key, nothing happens. And I just realized that eventhandler works properly when pressing arrow keys with ctrl. I searched everywhere, but found nothing. Can anyone help, please? My browser is Chrome v.96.+ React version 17.0.2, node v.16.13.1

 const HomePage = () => {
  const keyPressHandler = (e) => {
    if (e.repeat) return;
    if (e.key === "ArrowDown") {
      window.scrollBy(0, window.innerHeight);
    }
    if (e.key === "ArrowUp") {
      window.scrollBy(0, -window.innerHeight);
    }
  };

  return (
    <Container tabIndex="0" onKeyDown={keyPressHandler}>
      <div
        style={{ width: "100%", height: "100vh", backgroundColor: "green" }}
      />
      <div
        style={{ width: "100%", height: "100vh", backgroundColor: "gray" }}
      />
      <div style={{ width: "100%", height: "100vh", backgroundColor: "red" }} />
    </Container>
  );
};
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I fixed this creating new project and pasting this code there. I had some issues while installing react-icons dependencies and I stopped it manually. I think I get an error there

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