All Projects → jaredpalmer → React Simple Infinite Scroll

jaredpalmer / React Simple Infinite Scroll

Licence: mit
A brutally simple react infinite scroll component

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to React Simple Infinite Scroll

Vue List Scroller
Simple and easy to use Vue.js component for efficient rendering large lists
Stars: ✭ 65 (-50.76%)
Mutual labels:  infinite-scroll
Svelte Infinite Scroll
Infinite Scroll Component to Svelte
Stars: ✭ 102 (-22.73%)
Mutual labels:  infinite-scroll
Infinite Tree
A browser-ready tree library that can efficiently display a large amount of data using infinite scrolling.
Stars: ✭ 117 (-11.36%)
Mutual labels:  infinite-scroll
React Scroll
Effortless to get the twitter level infinite scroll implementation by only a bit of props
Stars: ✭ 74 (-43.94%)
Mutual labels:  infinite-scroll
Django Infinite Scroll Pagination
🌀 Pagination based on the seek method / keyset paging / offset-less pagination
Stars: ✭ 90 (-31.82%)
Mutual labels:  infinite-scroll
React Hooks Infinite Scroll
An example Infinite Scroll component, built using React Hooks
Stars: ✭ 103 (-21.97%)
Mutual labels:  infinite-scroll
React Ingrid
React infinite grid
Stars: ✭ 59 (-55.3%)
Mutual labels:  infinite-scroll
Vue Quick Loadmore
A pull-down refresh and pull-up infinite scroll component for Vue.js.--vue移动端下拉刷新上拉无限滚动加载插件,支持更换加载图片,保存和设置滚动距离等。
Stars: ✭ 129 (-2.27%)
Mutual labels:  infinite-scroll
Ngx Scrollspy
Angular ScrollSpy Service
Stars: ✭ 94 (-28.79%)
Mutual labels:  infinite-scroll
Pull To Refresh
ESPullToRefresh is developed and maintained by Vincent Li. If you have any questions or issues in using ESPullToRefresh, welcome to issue. If you want to contribute to ESPullToRefresh, Please submit Pull Request, I will deal with it as soon as possible.
Stars: ✭ 1,591 (+1105.3%)
Mutual labels:  infinite-scroll
Fancyscrollview
[Unity] A scrollview component that can implement highly flexible animations.
Stars: ✭ 1,216 (+821.21%)
Mutual labels:  infinite-scroll
Mithril Infinite
Infinite scroll for Mithril
Stars: ✭ 83 (-37.12%)
Mutual labels:  infinite-scroll
Justified Gallery
Javascript library to help creating high quality justified galleries of images. Used by thousands of websites as well as the photography community 500px.
Stars: ✭ 1,512 (+1045.45%)
Mutual labels:  infinite-scroll
React Native Snap Carousel
Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.
Stars: ✭ 9,151 (+6832.58%)
Mutual labels:  infinite-scroll
Ember Impagination
An Ember Addon that puts the fun back in asynchronous, paginated datasets
Stars: ✭ 123 (-6.82%)
Mutual labels:  infinite-scroll
React Infinite Tree
The infinite-tree library for React.
Stars: ✭ 63 (-52.27%)
Mutual labels:  infinite-scroll
Infinite scroll pagination
Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.
Stars: ✭ 102 (-22.73%)
Mutual labels:  infinite-scroll
React Responsive Carousel
React.js Responsive Carousel (with Swipe)
Stars: ✭ 1,962 (+1386.36%)
Mutual labels:  infinite-scroll
React Intersection List
React infinite scroll using the Intersection <Observer /> API
Stars: ✭ 125 (-5.3%)
Mutual labels:  infinite-scroll
Reactables
GigaTables is a ReactJS plug-in to help web-developers process table-data in applications and CMS, CRM, ERP or similar systems.
Stars: ✭ 112 (-15.15%)
Mutual labels:  infinite-scroll

React Simple Infinite Scroll

A brutally simple infinite scroll helper component.

Install

npm install react-simple-infinite-scroll --save

Usage

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).

Why not use windowing (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.

The Gist

<InfiniteScroll
  throttle={100}
  threshold={300}
  isLoading={this.state.isLoading}
  hasMore={!!this.state.cursor}
  onLoadMore={this.loadMore}
>
  {this.state.myArrayOfItems.map(item => <div>{/* ... */}</div>)}
</InfiniteScroll>
<InfiniteScroll
  throttle={100}
  threshold={300}
  isLoading={this.state.isLoading}
  hasMore={!!this.state.cursor}
  onLoadMore={this.loadMore}
  render={({ sentinel }) => (
    <section>
      {this.state.myArrayOfItems.map(item => <div>{/* ... */}</div>)}
      {sentinel}
    </section>
  )}
/>
// Small react-redux pseudocode
// `storeData` is information extracted from the store
const MyComponent = ({ sentinel, storeData }) => (
  <section>
    {storeData.entities}
    {sentinel}
  </section>
);

const ConnectedComponent = connect(/* ... */)(MyComponent);

<InfiniteScroll
  throttle={100}
  threshold={300}
  isLoading={storeData.isLoading}
  hasMore={storeData.hasMore}
  onLoadMore={() => boundActions.fetchMoreEntities(storeData.cursor)}
  component={ConnectedComponent}
/>

Full Example

import React from 'react'
import { InfiniteScroll } from 'react-simple-infinite-scroll'

export class MyInfiniteScrollExample extends React.Component {
  state = {
    items: [],
    isLoading: true,
    cursor: 0
  }

  componentDidMount() {
    // do some paginated fetch
    this.loadMore()
  }

  loadMore = () => {
    this.setState({ isLoading: true, error: undefined })
    fetch(`https://api.example.com/v1/items?from=${this.state.cursor}`)
      .then(res => res.json())
      .then(
        res => {
          this.setState(state => ({
            items: [...state.items, ...res.items],
            cursor: res.cursor,
            isLoading: false
          }))
        },
        error => {
          this.setState({ isLoading: false, error })
        }
    )
  }

  render() {
    return (
      <div>
        <InfiniteScroll
          throttle={100}
          threshold={300}
          isLoading={this.state.isLoading}
          hasMore={!!this.state.cursor}
          onLoadMore={this.loadMore}
        >
          {this.state.items.length > 0
            ? this.state.items.map(item => (
                <MyListItem key={item.id} title={item.title} />
              ))
            : null}
        </InfiniteScroll>
        {this.state.isLoading && (
          <MyLoadingState />
        )}
      </div>
    )
  }
}

API Reference

Props

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.

Alternatives

Author

Contributors

jared palmer
jared palmer
💻 📖 💡
pablo garcia
pablo garcia
💻 📖 💡

This project follows the all-contributors specification.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].