Skip to content

Commit d267fb8

Browse files
committed
upgrade readme with migration notes
1 parent b525654 commit d267fb8

File tree

1 file changed

+60
-11
lines changed

1 file changed

+60
-11
lines changed

README.md

Lines changed: 60 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,47 @@ npm:
1818
yarn:
1919
`yarn add react-bottom-scroll-listener`
2020

21+
## Migrating to V5
22+
23+
Version 5 is only a refactor for the hook to use an options parameter, instead
24+
of relying of function parameters which were starting to get out of hand.
25+
26+
#### If you are using the component, there are no breaking changes
27+
28+
If your hook looks like this:
29+
30+
```tsx
31+
useBottomScrollListener(callback, 0, 200, undefined, true);
32+
```
33+
34+
You will have to change it to use the options parameter:
35+
36+
```
37+
useBottomScrollListener(callback, {
38+
offset: 100,
39+
debounce: 0,
40+
triggerOnNoScroll: true
41+
})
42+
```
43+
44+
Remember that you can omit any values that are using the defaults! The defaults are ase following:
45+
46+
```
47+
offset: 0,
48+
debounce: 200,
49+
debounceOptions: { leading: true },
50+
triggerOnNoScroll: false,
51+
```
52+
53+
So for the average use case, you are probably only setting one of these values, so your hook
54+
might look like this:
55+
56+
```
57+
useBottomScrollListener(callback, { triggerOnNoScroll: true })
58+
```
59+
60+
You can refer to the Usage-section for more details.
61+
2162
## Usage
2263

2364
### Hook
@@ -47,19 +88,27 @@ import { useBottomScrollListener } from 'react-bottom-scroll-listener';
4788

4889
const scrollRef = useBottomScrollListener(callback);
4990

50-
<div ref={scrollRef}>Callback will be invoked when this container is scrolled to bottom.</div>
91+
<div ref={scrollRef}>Callback will be invoked when this container is scrolled to bottom.</div>;
5192
```
5293

5394
**Parameters**
5495

5596
```
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-
debounceOptions, // Overwrite the debounceOptions for lodash.debounce, default to { leading: true }
61-
triggerOnNoScroll,// If container is too short, enables a trigger of the callback if that happens, defaults to false
62-
) // returns React.MutableRefObject Optionally you can use this to pass to a element to use that as the scroll container
97+
useBottomScrollListener<T extends HTMLElement>(
98+
// Required callback that will be invoked when scrolled to bottom
99+
onBottom: () => void,
100+
// Options, entirely optional, you can provide one or several to overwrite the defaults
101+
options?: {
102+
// Offset from bottom of page in pixels. E.g. 300 will trigger onBottom 300px from the bottom of the page
103+
offset?: number
104+
// Optional debounce in milliseconds, defaults to 200ms
105+
debounce?: number
106+
// Overwrite the debounceOptions for lodash.debounce, default to { leading: true }
107+
debounceOptions?: DebounceOptions
108+
// If container is too short, enables a trigger of the callback if that happens, defaults to false
109+
triggerOnNoScroll?: boolean
110+
},
111+
); // returns React.MutableRefObject Optionally you can use this to pass to a element to use that as the scroll container
63112
```
64113

65114
### Component
@@ -73,7 +122,7 @@ Simply have the BottomScrollListener anywhere in your application and pass it a
73122
```jsx
74123
import BottomScrollListener from 'react-bottom-scroll-listener';
75124

76-
<BottomScrollListener onBottom={callback} />
125+
<BottomScrollListener onBottom={callback} />;
77126
```
78127

79128
#### On bottom of specific container
@@ -86,7 +135,7 @@ import BottomScrollListener from 'react-bottom-scroll-listener';
86135

87136
<BottomScrollListener onBottom={callback}>
88137
{(scrollRef) => <div ref={scrollRef}>Callback will be invoked when this container is scrolled to bottom.</div>}
89-
</BottomScrollListener>
138+
</BottomScrollListener>;
90139
```
91140

92141
> Those are some weird children, what's going on?
@@ -103,7 +152,7 @@ difficult to attach event listeners for scrolling to an arbitrary element.
103152
| debounce | number | 200 | milliseconds, how much debounce there should be on the callback |
104153
| offset | number | 0 | offset from bottom in pixels. E.g. 300 if it should invoke `onBottom` 300px before the bottom. |
105154
| debounceOptions | DebounceOptions | {leading: true} | see the lodash.debounce options: see https://lodash.com/docs/4.17.15#debounce |
106-
| triggerOnNoScroll | boolean | false | if container is too short, enables a trigger of the callback if that happens |
155+
| triggerOnNoScroll | boolean | false | if container is too short, enables a trigger of the callback if that happens |
107156
| children | React.Node _or_ Function | null | Not required, but you can use this to wrap your components. Most useful when you have some conditional rendering. If this is a function, that function will receive a React.RefObject that _needs_ to be passed to a child element. This element will then be used as the scroll container. |
108157

109158
# Migrating from 2.x.x to 3.x.x

0 commit comments

Comments
 (0)