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

115
Visualizações
Fire an event via click of an element

I've attached onClick in a component (it's a icon) inside div.
What i want is when that component is clicked, "wheel" event listener should be fired

   const [isArrowClicked,setIsArrowClicked] = useState(false);
   return(
     ...stuff
     <div className="downArrow" >
       <CgArrowLongDown onClick={()=>setIsArrowClicked(true)} />
     </div>
   )

This way i'm getting to know whether that icon is clicked or not.

Now i want to somehow call 'wheel' event listener something like this:

  if(isArrowClicked){
    window.addEventListener("wheel", (event) => {
       // stuff
    }
  }

But it should work for both, meaning when scroll is actually done using mouse as well as, when that component is clicked, 'wheel' event should be fired.

please help.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Im not sure if I understad what you are trying to achive. If you want to call the same function for both event you can use the same function for both event such as:

const myFunction = () => {
    // do stuff
}
window.addEventListener("wheel", myFunction)

and in the returned template:

<CgArrowLongDown onClick={myFunction} />

If you want to have the wheel listener to only do the stuff once the button is pushed you have to switch the if and the event listener in your code such as:

window.addEventListener("wheel", (event) => {
    if(isArrowClicked){
        // stuff
    }
}
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