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

106
Views
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 answers
Answer question

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 Report
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!