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?
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?
Share Improve this question asked Aug 13, 2020 at 13:49 Shashi SinghShashi Singh 311 gold badge1 silver badge2 bronze badges 1-
Try inlining your event handler,
<Component scroll={event => event.}
and see what type inference serves you up ;) – Aluan Haddad Commented Aug 13, 2020 at 13:53
2 Answers
Reset to default 4if 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 ment I wrote below another post here, you should not confuse wheel
and scroll
events.