我在滚动时添加了监听器,并尝试使用事件。如何描述类型而不是任何?
React 16.8.6 Tpescript 3.4
(请注意,我更正了原始文本中的一个拼写错误,并将其从“Tpescript”更改为“TypeScript”)const Component: FC<IProps> = ({ children, scrollOffset, getScrollTop, videoListScrollUpdate }) => {
const scroller = useRef<HTMLDivElement>(null)
useEffect(() => {
if (scrollOffset && scroller.current) {
scroller.current.scrollTop = scrollOffset
return
}
if (getScrollTop && scroller.current) {
scroller.current.addEventListener('scroll', (e: any) => getScrollTop(e.target.scrollTop))
}
}, [])
}
debounce
函数或Intersection Observer
API,因为滚动事件触发的次数实在是太多了。 - iamcastelli