File tree 1 file changed +8
-12
lines changed
packages/hooks/src/useInfiniteScroll
1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -106,20 +106,14 @@ const useInfiniteScroll = <TData extends Data>(
106
106
} ;
107
107
108
108
const scrollMethod = ( ) => {
109
- let el = getTargetElement ( target ) ;
110
- if ( ! el ) {
111
- return ;
112
- }
113
-
114
- el = el === document ? document . documentElement : el ;
109
+ const el = getTargetElement ( target ) ;
110
+ if ( ! el ) return ;
115
111
116
- const scrollTop = getScrollTop ( el ) ;
117
- const scrollHeight = getScrollHeight ( el ) ;
118
- const clientHeight = getClientHeight ( el ) ;
112
+ const targetEl = el === document ? document . documentElement : el ;
113
+ const scrollTop = getScrollTop ( targetEl ) ;
114
+ const scrollHeight = getScrollHeight ( targetEl ) ;
115
+ const clientHeight = getClientHeight ( targetEl ) ;
119
116
120
- if ( ! isScrollToTop && scrollHeight - scrollTop <= clientHeight + threshold ) {
121
- loadMore ( ) ;
122
- }
123
117
if ( isScrollToTop ) {
124
118
if (
125
119
lastScrollTop . current !== undefined &&
@@ -130,6 +124,8 @@ const useInfiniteScroll = <TData extends Data>(
130
124
}
131
125
lastScrollTop . current = scrollTop ;
132
126
scrollBottom . current = scrollHeight - scrollTop ;
127
+ } else if ( scrollHeight - scrollTop <= clientHeight + threshold ) {
128
+ loadMore ( ) ;
133
129
}
134
130
} ;
135
131
You can’t perform that action at this time.
0 commit comments