11# react-bottom-scroll-listener [ ![ NPM version] ( https://img.shields.io/npm/v/react-bottom-scroll-listener.svg?style=flat )] ( https://www.npmjs.com/package/react-bottom-scroll-listener ) [ ![ npm bundle size (minified)] ( https://img.shields.io/bundlephobia/minzip/react-bottom-scroll-listener.svg )] ( https://github.com/karl-run/react-bottom-scroll-listener )
22
3- A simple React component that lets you listen for when you have scrolled to the bottom.
3+ A simple ** React hook ** and ** React component** that lets you listen for when you have scrolled to the bottom.
44
55### Window
66
77![ Example] ( ./example.gif )
88
9-
10- ### Container
9+ ### Container
1110
1211![ Example] ( ./example_inner.gif )
1312
@@ -21,25 +20,71 @@ yarn:
2120
2221## Usage
2322
24- ### On bottom of entire screen
23+ ### Hook
2524
26- Simply have the BottomScrollListener anywhere in your application and pass it a function as ` onBottom ` -prop.
25+ [ Full example] ( /example/src/HookExample.js )
26+
27+ #### On bottom of entire screen
28+
29+ Use the hook in any functional component, the callback will be invoked
30+ when the user scrolls to the bottom of the document
2731
32+ ``` jsx
33+ import { useBottomScrollListener } from ' react-bottom-scroll-listener' ;
34+
35+ useBottomScrollListener (callback);
2836```
37+
38+ #### On bottom of specific container
39+
40+ Use the hook in any functional component, use the ref given from the hook
41+ and pass it to the element you want to use as a scroll container
42+
43+ The callback will be invoked when the user scrolls to the bottom of the container
44+
45+ ``` jsx
46+ import { useBottomScrollListener } from ' react-bottom-scroll-listener' ;
47+
48+ const containerRef = useBottomScrollListener (callback);
49+
50+ < div ref= {scrollRef}> Callback will be invoked when this container is scrolled to bottom.< / div>
51+ ```
52+
53+ ** Parameters**
54+
55+ ```
56+ useBottomScrollListener(
57+ onBottom, // Required callback that will be invoked when scrolled to bottom
58+ offset = 0, // Offset from bottom of page in pixels. E.g. 300 will trigger onBottom 300px from the bottom of the page
59+ debounce = 200, // Optional debounce in milliseconds, defaults to 200ms
60+ ) // returns React.MutableRefObject Optionally you can use this to pass to a element to use that as the scroll container
61+ ```
62+
63+ ### Component
64+
65+ [ Full example] ( /example/src/ComponentExample.js )
66+
67+ #### On bottom of entire screen
68+
69+ Simply have the BottomScrollListener anywhere in your application and pass it a function as ` onBottom ` -prop.
70+
71+ ``` jsx
72+ import BottomScrollListener from ' react-bottom-scroll-listener' ;
73+
2974< BottomScrollListener onBottom= {callback} / >
3075```
3176
32- ### On bottom of specific container
77+ #### On bottom of specific container
3378
3479Pass the BottomScrollListener a function inside the JSX_tag, receive the ` scrollRef ` in this function from the BottomScrollListener
3580and pass it to the component you want to listen for a scroll event on.
3681
37- ```
82+ ``` jsx
83+ import BottomScrollListener from ' react-bottom-scroll-listener' ;
84+
3885< BottomScrollListener onBottom= {callback}>
3986 {scrollRef => (
40- <div ref={scrollRef}>
41- Callback will be invoked when this container is scrolled to bottom.
42- </div>
87+ < div ref= {scrollRef}> Callback will be invoked when this container is scrolled to bottom.< / div>
4388 )}
4489< / BottomScrollListener>
4590```
0 commit comments