Skip to content

Commit b525654

Browse files
committed
refactor hook to use options object instead of function parameters
1 parent 064e542 commit b525654

File tree

16 files changed

+7103
-5734
lines changed

16 files changed

+7103
-5734
lines changed

.eslintrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"parser": "@typescript-eslint/parser",
33
"extends": [
4-
"standard",
5-
"standard-react",
6-
"plugin:prettier/recommended",
4+
"eslint:recommended",
5+
"plugin:@typescript-eslint/recommended",
76
"prettier/standard",
87
"prettier/react",
8+
"plugin:prettier/recommended",
99
"plugin:@typescript-eslint/eslint-recommended"
1010
],
1111
"env": {

.github/workflows/main.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: CI
2+
3+
on: [push]
4+
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v2
10+
- run: yarn
11+
- run: yarn test
12+
- uses: devmasx/[email protected]
13+
with:
14+
type: lcov
15+
result_path: coverage/lcov.info
16+
min_coverage: 1
17+
token: ${{secrets.GITHUB_TOKEN}}

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ node_modules
88
build
99
dist
1010
.rpt2_cache
11+
.eslintcache
1112

1213
# misc
1314
.DS_Store

.prettierrc

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
{
2-
"semi": false,
32
"tabWidth": 2,
43
"trailingComma": "all",
54
"singleQuote": true,

example/src/App.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import React, { useState } from 'react'
2-
import Toggle from 'react-toggle'
1+
import React, { useState } from 'react';
2+
import Toggle from 'react-toggle';
33

4-
import ComponentExample from './ComponentExample'
5-
import HookExample from './HookExample'
4+
import ComponentExample from './ComponentExample';
5+
import HookExample from './HookExample';
66

77
const App = () => {
8-
const [hookExample, setHookExample] = useState(true)
9-
const [alertOnBottom, setAlertOnBottom] = useState(true)
8+
const [hookExample, setHookExample] = useState(true);
9+
const [alertOnBottom, setAlertOnBottom] = useState(true);
1010

1111
return (
1212
<div>
@@ -15,17 +15,17 @@ const App = () => {
1515
<div className="right-toggle-box">
1616
<label htmlFor="alert-state">
1717
<span>Use {alertOnBottom ? 'alert dialog' : 'console.log'}</span>
18-
<Toggle id="alert-state" checked={alertOnBottom} onChange={() => setAlertOnBottom(b => !b)} />
18+
<Toggle id="alert-state" checked={alertOnBottom} onChange={() => setAlertOnBottom((b) => !b)} />
1919
</label>
2020
<label htmlFor="use-hook-state">
2121
<span>Use {hookExample ? 'hook' : 'component'}</span>
22-
<Toggle id="use-hook-state" checked={hookExample} onChange={() => setHookExample(b => !b)} />
22+
<Toggle id="use-hook-state" checked={hookExample} onChange={() => setHookExample((b) => !b)} />
2323
</label>
2424
</div>
2525
</header>
2626
{hookExample ? <HookExample alertOnBottom={alertOnBottom} /> : <ComponentExample alertOnBottom={alertOnBottom} />}
2727
</div>
28-
)
29-
}
28+
);
29+
};
3030

31-
export default App
31+
export default App;

example/src/ComponentExample.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
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 (
@@ -39,7 +39,7 @@ class ComponentExample extends Component {
3939
{/* If you want to listen for the bottom of a specific container you need to forward
4040
a scrollRef as a ref to your container */}
4141
<BottomScrollListener onBottom={this.handleContainerOnBottom}>
42-
{scrollRef => (
42+
{(scrollRef) => (
4343
<div ref={scrollRef} className="inner-scroll-example">
4444
<h4>Callback when this container hits bottom</h4>
4545
<div>Scroll down! ▼▼▼</div>
@@ -50,8 +50,8 @@ class ComponentExample extends Component {
5050
)}
5151
</BottomScrollListener>
5252
</div>
53-
)
53+
);
5454
}
5555
}
5656

57-
export default ComponentExample
57+
export default ComponentExample;

example/src/HookExample.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
import React, { useCallback } from 'react'
1+
import React, { useCallback } from 'react';
22

3-
import { useBottomScrollListener } from 'react-bottom-scroll-listener'
3+
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) {
10-
alert('Bottom hit!')
10+
alert('Bottom hit!');
1111
}
12-
}, [alertOnBottom])
12+
}, [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) {
18-
alert('Bottom of this container hit!')
18+
alert('Bottom of this container hit!');
1919
}
20-
}, [alertOnBottom])
20+
}, [alertOnBottom]);
2121

2222
/* This will trigger handleOnDocumentBottom when the body of the page hits the bottom */
23-
useBottomScrollListener(handleOnDocumentBottom)
23+
useBottomScrollListener(handleOnDocumentBottom);
2424

2525
/* 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);
2727

2828
return (
2929
<div className="root">
@@ -45,7 +45,7 @@ const HookExample = ({ alertOnBottom }) => {
4545
</div>
4646
</div>
4747
</div>
48-
)
49-
}
48+
);
49+
};
5050

51-
export default HookExample
51+
export default HookExample;

example/src/index.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react'
2-
import ReactDOM from 'react-dom'
1+
import React from 'react';
2+
import ReactDOM from 'react-dom';
33

4-
import './index.css'
5-
import App from './App'
4+
import './index.css';
5+
import App from './App';
66

7-
ReactDOM.render(<App />, document.getElementById('root'))
7+
ReactDOM.render(<App />, document.getElementById('root'));

0 commit comments

Comments
 (0)