I know we can use event listener and work with ScrollEvent.
But suppose following method:
handleScroll =(event:any):void=>{
const target = event.target;
// further code goes her
}
I want to use event type instead of any so what should be its type?
if you aim to catch the mouse-wheel scroll event then you can use this type.
handleScroll = (event: WheelEvent): void =>
If you are not doing this in React then you would use
handleScroll = (event: Event):void => {
const target = event.target;
// further code goes here
}
If you using React and the scrolling is being done in a <div>
then you would use
handleScroll = (event: React.UIEvent<HTMLDivElement>):void => {
const target = event.target;
// further code goes here
}
If the event is occuring on another type of element (and using React) then you should substitute that for <HTMLDivElement>
.
As per a comment I wrote below another post here, you should not confuse wheel
and scroll
events.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With