Home > Mobile >  How to type scroll event in React?
How to type scroll event in React?

Time:12-06

Tell me how to correctly type the scrollHandler function in this case.

`

useEffect(() => {
  document.addEventListener('submit', scrollHandler);

  return () => document.removeEventListener('scroll', scrollHandler)
})

const scrollHandler = (e: React.UIEvent<??>) => {
  console.log(e)
}

` Code example on CodeSandBox here

I have tried React.UIEvent React.UIEvent and etc. but it doesn't work, it throws an error :(

Thanks in advance to everyone

CodePudding user response:

const scrollHandler = (e: Event) => { console.log(e) }

  • Related