@@ -37,6 +37,10 @@ export type VirtualListProps<ITEM> = {
3737 * Minimum distance for triggering a calculation when scrolling.
3838 */
3939 triggerDistance ?: number ,
40+ /**
41+ * listen to scroll event.
42+ */
43+ onScroll : typeof document . onscroll ,
4044 className ?: string ,
4145 style ?: React . CSSProperties ,
4246} & OptionalKeys < typeof defaultProps >
@@ -124,21 +128,21 @@ export const VirtualList = forwardRef(function <ITEM>(
124128 }
125129 } , [ props . itemSize , props . items , forceRerender ] ) ;
126130 //
127- const handleScroll = ( ) => {
131+ const handleScroll = function ( event : unknown ) {
128132 if ( ignoreScrollOnce . current ) {
129133 ignoreScrollOnce . current = false
130134 return
131135 }
132136 setlistSize ( list . current ! . clientHeight )
133137 const scrollTop2 = list . current ! . scrollTop
134138 if ( Math . abs ( prevScrollTop . current - scrollTop2 ) > ( props . triggerDistance ?? itemSize ) ) {
135- console . log ( 'triggerd' ) ;
136-
137139 setscrollTop ( scrollTop2 )
138140 prevScrollTop . current = scrollTop2
139141 } else if ( scrollToIndexRef . current ) {
140142 setforceRerender ( [ ] )
141143 }
144+ // @ts -ignore
145+ props . onScroll ?. call ( this , event )
142146 }
143147 //
144148 useImperativeHandle ( ref , ( ) => ( {
@@ -151,7 +155,7 @@ export const VirtualList = forwardRef(function <ITEM>(
151155 } ,
152156 forceUpdate ( ) {
153157 setforceRerender ( [ ] )
154- }
158+ } ,
155159 } ) , [ itemSize ] ) ;
156160 useLayoutEffect ( ( ) => {
157161 if ( scrollToIndexRef . current ) {
@@ -175,4 +179,4 @@ export const VirtualList = forwardRef(function <ITEM>(
175179} )
176180
177181// @ts -ignore
178- VirtualList . defaultProps = defaultProps
182+ VirtualList . defaultProps = defaultProps
0 commit comments