Skip to content

Commit f07f86a

Browse files
committed
chore: remove deprecated ReactDOM.render in example app
1 parent 21140d3 commit f07f86a

File tree

7 files changed

+61
-45
lines changed

7 files changed

+61
-45
lines changed

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
</noscript>
1616

1717
<div id="root"></div>
18-
<script type="module" src="/src/index.jsx"></script>
18+
<script type="module" src="/src/main.jsx"></script>
1919
</body>
2020
</html>

example/src/App.jsx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,24 @@ const App = () => {
1212
<div>
1313
<header className="bg-purple-700 p-2 flex gap-3 flex-col md:flex-row justify-between m-2 rounded text-white items-center border-2 border-purple-950">
1414
<h1 className="text-xl">react-bottom-scroll-listener</h1>
15-
<div className="flex gap-6">
16-
<label htmlFor="alert-state" className="flex justify-center gap-3">
15+
<div className="flex gap-6 pt-2">
16+
<label
17+
htmlFor="alert-state"
18+
className="flex justify-center gap-3 flex-col md:flex-row items-center md:items-start"
19+
>
1720
<span>Use {alertOnBottom ? 'alert dialog' : 'console.log'}</span>
18-
<Toggle id="alert-state" checked={alertOnBottom} onChange={() => setAlertOnBottom((b) => !b)} />
21+
<div>
22+
<Toggle id="alert-state" checked={alertOnBottom} onChange={() => setAlertOnBottom((b) => !b)} />
23+
</div>
1924
</label>
20-
<label htmlFor="use-hook-state" className="flex justify-center gap-3">
25+
<label
26+
htmlFor="use-hook-state"
27+
className="flex justify-center gap-3 flex-col md:flex-row items-center md:items-start"
28+
>
2129
<span>Use {hookExample ? 'hook' : 'component'}</span>
22-
<Toggle id="use-hook-state" checked={hookExample} onChange={() => setHookExample((b) => !b)} />
30+
<div>
31+
<Toggle id="use-hook-state" checked={hookExample} onChange={() => setHookExample((b) => !b)} />
32+
</div>
2333
</label>
2434
</div>
2535
</header>

example/src/ComponentExample.jsx

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,60 @@
1-
import React, { Component } from 'react';
1+
import React, { Component } from 'react'
22

3-
import 'react-toggle/style.css';
3+
import 'react-toggle/style.css'
44

5-
import { BottomScrollListener } from 'react-bottom-scroll-listener';
5+
import { BottomScrollListener } from 'react-bottom-scroll-listener'
66

77
class ComponentExample extends Component {
88
handleOnDocumentBottom = () => {
9-
console.log('I am at bottom! ' + Math.round(performance.now()));
9+
console.log(`I am at bottom! ${Math.round(performance.now())}`)
1010

1111
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')
1313
}
14-
};
14+
}
1515

1616
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())}`)
1818

1919
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')
2121
}
22-
};
22+
}
2323

2424
render() {
2525
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>
3927
{/* If you want to listen for the bottom of a specific container you need to forward
4028
a scrollRef as a ref to your container */}
4129
<BottomScrollListener onBottom={this.handleContainerOnBottom}>
4230
{(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>
4940
</div>
5041
)}
5142
</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} />
5255
</div>
53-
);
56+
)
5457
}
5558
}
5659

57-
export default ComponentExample;
60+
export default ComponentExample

example/src/HookExample.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import { useBottomScrollListener } from 'react-bottom-scroll-listener'
44

55
const HookExample = ({ alertOnBottom }) => {
66
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())}`)
88

99
if (alertOnBottom) {
1010
alert('Bottom hit!')
1111
}
1212
}, [alertOnBottom])
1313

1414
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())}`)
1616

1717
if (alertOnBottom) {
1818
alert('Bottom of this container hit!')
File renamed without changes.

example/src/index.jsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

example/src/main.jsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import './global.css';
2+
3+
import React from 'react';
4+
import { createRoot } from 'react-dom/client';
5+
6+
import App from './App';
7+
8+
const container = document.getElementById('root');
9+
const root = createRoot(container); // createRoot(container!) if you use TypeScript
10+
root.render(<App />);

0 commit comments

Comments
 (0)