reactjstypescripteventsevent-handlinguievent

How to type scroll event in React?


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


Solution

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