Skip to content

Commit f5e1341

Browse files
committed
docs: update README for v7, add What's new section
1 parent ca97ad0 commit f5e1341

1 file changed

Lines changed: 40 additions & 6 deletions

File tree

README.md

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ added. An infinite-scroll that actually works and super-simple to integrate!
3838
</p>
3939
}
4040
// below props only if you need pull down functionality
41-
refreshFunction={this.refresh}
41+
refreshFunction={refresh}
4242
pullDownToRefresh
4343
pullDownToRefreshThreshold={50}
4444
pullDownToRefreshContent={
@@ -66,15 +66,15 @@ added. An infinite-scroll that actually works and super-simple to integrate!
6666
>
6767
{/*Put the scroll bar always on the bottom*/}
6868
<InfiniteScroll
69-
dataLength={this.state.items.length}
70-
next={this.fetchMoreData}
69+
dataLength={items.length}
70+
next={fetchMoreData}
7171
style={{ display: 'flex', flexDirection: 'column-reverse' }} //To put endMessage and loader to the top.
72-
inverse={true} //
72+
inverse={true}
7373
hasMore={true}
7474
loader={<h4>Loading...</h4>}
7575
scrollableTarget="scrollableDiv"
7676
>
77-
{this.state.items.map((_, index) => (
77+
{items.map((_, index) => (
7878
<div style={style} key={index}>
7979
div - #{index}
8080
</div>
@@ -89,6 +89,40 @@ The `InfiniteScroll` component can be used in three ways.
8989
- If your **scrollable** content is being rendered within a parent element that is already providing overflow scrollbars, you can set the `scrollableTarget` prop to reference the DOM element and use it's scrollbars for fetching more data.
9090
- Without setting either the `height` or `scrollableTarget` props, the scroll will happen at `document.body` like _Facebook's_ timeline scroll.
9191

92+
## What's new in v7
93+
94+
### IntersectionObserver-based triggering
95+
96+
`next()` is now triggered by an `IntersectionObserver` watching an invisible sentinel element at the bottom of the list (top for `inverse` mode), rather than a scroll event listener. This means:
97+
98+
- The threshold is checked once when the sentinel enters the viewport, not on every scroll tick.
99+
- No missed triggers when content loads fast enough to skip the threshold.
100+
- Better performance — no work done while the user is scrolling through content that is far from the threshold.
101+
102+
### Zero runtime dependencies
103+
104+
`throttle-debounce` has been removed. The package now ships with **zero runtime dependencies**. The `onScroll` callback receives every scroll event directly without throttling.
105+
106+
### `scrollableTarget` accepts `HTMLElement` directly
107+
108+
Previously `scrollableTarget` only accepted a string element ID. It now accepts `HTMLElement | string | null`, so you can pass a ref value directly:
109+
110+
```jsx
111+
const ref = useRef(null);
112+
// ...
113+
<div ref={ref} style={{ height: 300, overflow: 'auto' }}>
114+
<InfiniteScroll scrollableTarget={ref.current} ...>
115+
{items}
116+
</InfiniteScroll>
117+
</div>
118+
```
119+
120+
### Rewritten as a function component
121+
122+
The component is now a React function component. The public prop API is unchanged — no migration needed.
123+
124+
---
125+
92126
## docs version wise
93127

94128
[3.0.2](docs/README-3.0.2.md)
@@ -114,7 +148,7 @@ The `InfiniteScroll` component can be used in three ways.
114148
| **dataLength** | number | set the length of the data.This will unlock the subsequent calls to next. |
115149
| **loader** | node | you can send a loader component to show while the component waits for the next load of data. e.g. `<h3>Loading...</h3>` or any fancy loader element |
116150
| **scrollThreshold** | number &#124; string | A threshold value defining when `InfiniteScroll` will call `next`. Default value is `0.8`. It means the `next` will be called when user comes below 80% of the total height. If you pass threshold in pixels (`scrollThreshold="200px"`), `next` will be called once you scroll at least (100% - scrollThreshold) pixels down. |
117-
| **onScroll** | function | a function that will listen to the scroll event on the scrolling container. Note that the scroll event is throttled, so you may not receive as many events as you would expect. |
151+
| **onScroll** | function | a function that will listen to the scroll event on the scrolling container. |
118152
| **endMessage** | node | this message is shown to the user when he has seen all the records which means he's at the bottom and `hasMore` is `false` |
119153
| **className** | string | add any custom class you want |
120154
| **style** | object | any style which you want to override |

0 commit comments

Comments
 (0)