Skip to content

Commit 8043161

Browse files
committed
Add option for triggering onBottom when page has no scrollbar
1 parent 7da5630 commit 8043161

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/hook/index.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ const createCallback = (debounce: number, handleOnScroll: () => void, options: D
1818
* @param offset Offset from bottom of page in pixels. E.g. 300 will trigger onBottom 300px from the bottom of the page
1919
* @param debounce Optional debounce in milliseconds, defaults to 200ms
2020
* @param debounceOptions Options passed to lodash.debounce, see https://lodash.com/docs/4.17.15#debounce
21+
* @param triggerOnNoScroll Triggers the onBottom callback when the page has no scrollbar
2122
* @return React.MutableRefObject Optionally you can use this to pass to a element to use that as the scroll container
2223
*/
2324
function useBottomScrollListener<T extends HTMLElement>(
2425
onBottom: () => void,
2526
offset: number = 0,
2627
debounce: number = 200,
2728
debounceOptions: DebounceOptions = { leading: true },
29+
triggerOnNoScroll: boolean = false
2830
) {
2931
const debouncedOnBottom = useMemo(() => createCallback(debounce, onBottom, debounceOptions), [debounce, onBottom])
3032
const containerRef = useRef<T>(null)
@@ -57,6 +59,10 @@ function useBottomScrollListener<T extends HTMLElement>(
5759
window.addEventListener('scroll', handleOnScroll)
5860
}
5961

62+
if (triggerOnNoScroll) {
63+
handleOnScroll()
64+
}
65+
6066
return () => {
6167
if (ref != null) {
6268
ref.removeEventListener('scroll', handleOnScroll)

0 commit comments

Comments
 (0)