Gathering detailed insights and metrics for react-simple-infinite-scroll
Gathering detailed insights and metrics for react-simple-infinite-scroll
Gathering detailed insights and metrics for react-simple-infinite-scroll
Gathering detailed insights and metrics for react-simple-infinite-scroll
npm install react-simple-infinite-scroll
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
142 Stars
23 Commits
25 Forks
3 Watching
16 Branches
7 Contributors
Updated on 25 Aug 2024
Minified
Minified + Gzipped
TypeScript (76.91%)
JavaScript (23.09%)
Cumulative downloads
Total Downloads
Last day
100%
6
Compared to previous day
Last week
8.2%
53
Compared to previous week
Last month
-1.7%
178
Compared to previous month
Last year
-46.9%
2,357
Compared to previous year
A brutally simple infinite scroll helper component.
1npm install react-simple-infinite-scroll --save
This component uses a "sentinel" div
(with a React ref) that calls getBoundingClientRect()
to measure its position and fire off a callback when it becomes visible again. Note: this package eventually becomes somewhat inefficient on very very very large lists because it keeps adding nodes to the DOM. However, this package is extremely valuable for situations when a windowing technique is not possible and when a user is going to realistically scroll a few hundred rows (and not thousands of rows).
react-virtualized
)?If you can, you probably should. However, windowing only works when you know the total number of items in the result set ahead of time. This isn't always possible. For example, let's say you have a MongoDB database where you cannot efficiently return the total number of documents in a given query. All your API returns is a cursor (so you can know is if there is another page or not). While this would prevent you from using windowing/react-virtualized
, react-simple-infinite-scroll
will work just fine.
1<InfiniteScroll 2 throttle={100} 3 threshold={300} 4 isLoading={this.state.isLoading} 5 hasMore={!!this.state.cursor} 6 onLoadMore={this.loadMore} 7> 8 {this.state.myArrayOfItems.map(item => <div>{/* ... */}</div>)} 9</InfiniteScroll>
1<InfiniteScroll 2 throttle={100} 3 threshold={300} 4 isLoading={this.state.isLoading} 5 hasMore={!!this.state.cursor} 6 onLoadMore={this.loadMore} 7 render={({ sentinel }) => ( 8 <section> 9 {this.state.myArrayOfItems.map(item => <div>{/* ... */}</div>)} 10 {sentinel} 11 </section> 12 )} 13/>
1// Small react-redux pseudocode 2// `storeData` is information extracted from the store 3const MyComponent = ({ sentinel, storeData }) => ( 4 <section> 5 {storeData.entities} 6 {sentinel} 7 </section> 8); 9 10const ConnectedComponent = connect(/* ... */)(MyComponent); 11 12<InfiniteScroll 13 throttle={100} 14 threshold={300} 15 isLoading={storeData.isLoading} 16 hasMore={storeData.hasMore} 17 onLoadMore={() => boundActions.fetchMoreEntities(storeData.cursor)} 18 component={ConnectedComponent} 19/>
1import React from 'react' 2import { InfiniteScroll } from 'react-simple-infinite-scroll' 3 4export class MyInfiniteScrollExample extends React.Component { 5 state = { 6 items: [], 7 isLoading: true, 8 cursor: 0 9 } 10 11 componentDidMount() { 12 // do some paginated fetch 13 this.loadMore() 14 } 15 16 loadMore = () => { 17 this.setState({ isLoading: true, error: undefined }) 18 fetch(`https://api.example.com/v1/items?from=${this.state.cursor}`) 19 .then(res => res.json()) 20 .then( 21 res => { 22 this.setState(state => ({ 23 items: [...state.items, ...res.items], 24 cursor: res.cursor, 25 isLoading: false 26 })) 27 }, 28 error => { 29 this.setState({ isLoading: false, error }) 30 } 31 ) 32 } 33 34 render() { 35 return ( 36 <div> 37 <InfiniteScroll 38 throttle={100} 39 threshold={300} 40 isLoading={this.state.isLoading} 41 hasMore={!!this.state.cursor} 42 onLoadMore={this.loadMore} 43 > 44 {this.state.items.length > 0 45 ? this.state.items.map(item => ( 46 <MyListItem key={item.id} title={item.title} /> 47 )) 48 : null} 49 </InfiniteScroll> 50 {this.state.isLoading && ( 51 <MyLoadingState /> 52 )} 53 </div> 54 ) 55 } 56}
hasMore: boolean
Required
Specifies if there are more entities to load.
isLoading: boolean
Required
When true
, onLoadMore()
will not be executed on scroll.
onLoadMore: () => void
Required
Called when the user has scrolled all the way to the end. This happens when the sentinel
has reached the threshold
.
threshold?: number
Scroll threshold. Number of pixels before the sentinel
reaches the viewport to trigger onLoadMore()
.
throttle?: number = 64
Defaults to 64
. Scroll handler will be executed at most once per the number of milliseconds specified.
Warning: Making this number closer to zero can decrease performance due to a force reflow caused by getBoundingClientRect()
, see more properties that can cause this issue in this gist by Paul Irish.
render?: (props: ScrollProps) => React.ReactNode
Callback used for convenient inline rendering and wrapping. Arguments passed Object: { sentinel, children }
. Use this if you have a more complex layout where the sentinel
needs to be injected.
Warning: The sentinel
must be rendered (injected into the DOM) in order for this library to work properly, failing to do so will result in errors and unexpected side effects.
component?: React.ComponentType<ScrollProps>
React component. Similar to the render()
prop, this component will receive Object: { sentinel, children }
as props. Note that render()
prop has precedence over this property, meaning that if both are present, component
will not be rendered.
Warning: The sentinel
must be rendered (injected into the DOM) in order for this library to work properly, failing to do so will result in errors and unexpected side effects.
jared palmer 💻 📖 💡 | pablo garcia 💻 📖 💡 |
---|
This project follows the all-contributors specification.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 7/10 approved changesets -- score normalized to 7
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Reason
69 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-11-18
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More