|
1 | | -import React, { Component } from 'react'; |
| 1 | +import React, { Component } from 'react' |
2 | 2 |
|
3 | | -import 'react-toggle/style.css'; |
| 3 | +import 'react-toggle/style.css' |
4 | 4 |
|
5 | | -import { BottomScrollListener } from 'react-bottom-scroll-listener'; |
| 5 | +import { BottomScrollListener } from 'react-bottom-scroll-listener' |
6 | 6 |
|
7 | 7 | class ComponentExample extends Component { |
8 | 8 | handleOnDocumentBottom = () => { |
9 | | - console.log('I am at bottom! ' + Math.round(performance.now())); |
| 9 | + console.log(`I am at bottom! ${Math.round(performance.now())}`) |
10 | 10 |
|
11 | 11 | if (this.props.alertOnBottom) { |
12 | | - alert('Bottom hit! Too slow? Reduce "debounce" value in props'); |
| 12 | + alert('Bottom hit! Too slow? Reduce "debounce" value in props') |
13 | 13 | } |
14 | | - }; |
| 14 | + } |
15 | 15 |
|
16 | 16 | handleContainerOnBottom = () => { |
17 | | - console.log('I am at bottom in optional container! ' + Math.round(performance.now())); |
| 17 | + console.log(`I am at bottom in optional container! ${Math.round(performance.now())}`) |
18 | 18 |
|
19 | 19 | if (this.props.alertOnBottom) { |
20 | | - alert('Bottom of this container hit! Too slow? Reduce "debounce" value in props'); |
| 20 | + alert('Bottom of this container hit! Too slow? Reduce "debounce" value in props') |
21 | 21 | } |
22 | | - }; |
| 22 | + } |
23 | 23 |
|
24 | 24 | render() { |
25 | 25 | return ( |
26 | | - <div className="root"> |
27 | | - <div className="scroll-box"> |
28 | | - <h1>Component example</h1> |
29 | | - <h2>Callback when document hits bottom</h2> |
30 | | - <div>Scroll down! ▼▼▼</div> |
31 | | - <div>A bit more... ▼▼</div> |
32 | | - <div>Almost there... ▼</div> |
33 | | - <div>You've reached the bottom!</div> |
34 | | - </div> |
35 | | - |
36 | | - {/* When you only want to listen to the bottom of "document", you can put it anywhere */} |
37 | | - <BottomScrollListener onBottom={this.handleOnDocumentBottom} /> |
38 | | - |
| 26 | + <div> |
39 | 27 | {/* If you want to listen for the bottom of a specific container you need to forward |
40 | 28 | a scrollRef as a ref to your container */} |
41 | 29 | <BottomScrollListener onBottom={this.handleContainerOnBottom}> |
42 | 30 | {(scrollRef) => ( |
43 | | - <div ref={scrollRef} className="inner-scroll-example"> |
44 | | - <h4>Callback when this container hits bottom</h4> |
45 | | - <div>Scroll down! ▼▼▼</div> |
46 | | - <div>A bit more... ▼▼</div> |
47 | | - <div>Almost there... ▼</div> |
48 | | - <div>You've reached the bottom!</div> |
| 31 | + <div |
| 32 | + ref={scrollRef} |
| 33 | + 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" |
| 34 | + > |
| 35 | + <h4 className="font-bold">Callback when this container hits bottom</h4> |
| 36 | + <div className="h-44">Scroll down! ▼▼▼</div> |
| 37 | + <div className="h-44">A bit more... ▼▼</div> |
| 38 | + <div className="h-44">Almost there... ▼</div> |
| 39 | + <div className="h-44">You've reached the bottom!</div> |
49 | 40 | </div> |
50 | 41 | )} |
51 | 42 | </BottomScrollListener> |
| 43 | + |
| 44 | + <div className="mt-16 m-8"> |
| 45 | + <h1 className="text-xl font-bold">Component example</h1> |
| 46 | + <h2 className="font-bold">Callback when document hits bottom</h2> |
| 47 | + <div className="h-96 border-2 border-purple-950 mt-4 p-4">Scroll down! ▼▼▼</div> |
| 48 | + <div className="h-96 border-2 border-purple-950 mt-4 p-4">A bit more... ▼▼</div> |
| 49 | + <div className="h-96 border-2 border-purple-950 mt-4 p-4">Almost there... ▼</div> |
| 50 | + <div className="h-96 border-2 border-purple-950 mt-4 p-4">You've reached the bottom!</div> |
| 51 | + </div> |
| 52 | + |
| 53 | + {/* When you only want to listen to the bottom of "document", you can put it anywhere */} |
| 54 | + <BottomScrollListener onBottom={this.handleOnDocumentBottom} /> |
52 | 55 | </div> |
53 | | - ); |
| 56 | + ) |
54 | 57 | } |
55 | 58 | } |
56 | 59 |
|
57 | | -export default ComponentExample; |
| 60 | +export default ComponentExample |
0 commit comments