|
1 | | -import React, { useCallback } from 'react'; |
| 1 | +import React, { useCallback } from 'react' |
2 | 2 |
|
3 | | -import { useBottomScrollListener } from 'react-bottom-scroll-listener'; |
| 3 | +import { useBottomScrollListener } from 'react-bottom-scroll-listener' |
4 | 4 |
|
5 | 5 | const HookExample = ({ alertOnBottom }) => { |
6 | 6 | const handleOnDocumentBottom = useCallback(() => { |
7 | | - console.log('I am at bottom! ' + Math.round(performance.now())); |
| 7 | + console.log('I am at bottom! ' + Math.round(performance.now())) |
8 | 8 |
|
9 | 9 | if (alertOnBottom) { |
10 | | - alert('Bottom hit!'); |
| 10 | + alert('Bottom hit!') |
11 | 11 | } |
12 | | - }, [alertOnBottom]); |
| 12 | + }, [alertOnBottom]) |
13 | 13 |
|
14 | 14 | const handleContainerOnBottom = useCallback(() => { |
15 | | - console.log('I am at bottom in optional container! ' + Math.round(performance.now())); |
| 15 | + console.log('I am at bottom in optional container! ' + Math.round(performance.now())) |
16 | 16 |
|
17 | 17 | if (alertOnBottom) { |
18 | | - alert('Bottom of this container hit!'); |
| 18 | + alert('Bottom of this container hit!') |
19 | 19 | } |
20 | | - }, [alertOnBottom]); |
| 20 | + }, [alertOnBottom]) |
21 | 21 |
|
22 | 22 | /* This will trigger handleOnDocumentBottom when the body of the page hits the bottom */ |
23 | | - useBottomScrollListener(handleOnDocumentBottom); |
| 23 | + useBottomScrollListener(handleOnDocumentBottom) |
24 | 24 |
|
25 | 25 | /* This will trigger handleOnContainerBottom when the container that is passed the ref hits the bottom */ |
26 | | - const containerRef = useBottomScrollListener(handleContainerOnBottom); |
| 26 | + const containerRef = useBottomScrollListener(handleContainerOnBottom) |
27 | 27 |
|
28 | 28 | return ( |
29 | | - <div className="root"> |
30 | | - <div className="scroll-box"> |
31 | | - <h1>Hook example</h1> |
32 | | - <h2>Callback when document hits bottom</h2> |
33 | | - <div>Scroll down! ▼▼▼</div> |
34 | | - <div>A bit more... ▼▼</div> |
35 | | - <div>Almost there... ▼</div> |
36 | | - <div>You've reached the bottom!</div> |
| 29 | + <div> |
| 30 | + <div |
| 31 | + ref={containerRef} |
| 32 | + className="md:absolute m-8 md:m-0 top-20 right-12 h-72 md:w-60 bg-purple-200 overflow-auto p-4 border-2 border-purple-950 rounded" |
| 33 | + > |
| 34 | + <h4 className="font-bold">Callback when this container hits bottom</h4> |
| 35 | + <div className="h-44">Scroll down! ▼▼▼</div> |
| 36 | + <div className="h-44">A bit more... ▼▼</div> |
| 37 | + <div className="h-44">Almost there... ▼</div> |
| 38 | + <div className="h-44">You've reached the bottom!</div> |
37 | 39 | </div> |
38 | | - <div> |
39 | | - <div ref={containerRef} className="inner-scroll-example"> |
40 | | - <h4>Callback when this container hits bottom</h4> |
41 | | - <div>Scroll down! ▼▼▼</div> |
42 | | - <div>A bit more... ▼▼</div> |
43 | | - <div>Almost there... ▼</div> |
44 | | - <div>You've reached the bottom!</div> |
45 | | - </div> |
| 40 | + <div className="mt-16 m-8"> |
| 41 | + <h1 className="text-xl font-bold">Hook example</h1> |
| 42 | + <h2 className="font-bold">Callback when document hits bottom</h2> |
| 43 | + <div className="h-96 border-2 border-purple-950 mt-4 p-4">Scroll down! ▼▼▼</div> |
| 44 | + <div className="h-96 border-2 border-purple-950 mt-4 p-4">A bit more... ▼▼</div> |
| 45 | + <div className="h-96 border-2 border-purple-950 mt-4 p-4">Almost there... ▼</div> |
| 46 | + <div className="h-96 border-2 border-purple-950 mt-4 p-4">You've reached the bottom!</div> |
46 | 47 | </div> |
47 | 48 | </div> |
48 | | - ); |
49 | | -}; |
| 49 | + ) |
| 50 | +} |
50 | 51 |
|
51 | | -export default HookExample; |
| 52 | +export default HookExample |
0 commit comments