All Projects → CurationCorp → react-use-infinite-loader

CurationCorp / react-use-infinite-loader

Licence: MIT license
♾️ 📃 ⏳ Super lightweight infinite loading hook for React apps

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to react-use-infinite-loader

Od Virtualscroll
🚀 Observable-based virtual scroll implementation in Angular
Stars: ✭ 133 (+786.67%)
Mutual labels:  infinite-scroll
Window Table
Windowing Table for React based on React Window
Stars: ✭ 160 (+966.67%)
Mutual labels:  infinite-scroll
Wordpress Ajax Load More
🔥 WordPress infinite scroll with Ajax Load More - the ultimate solution to add infinite scroll functionality to your WordPress powered website.
Stars: ✭ 222 (+1380%)
Mutual labels:  infinite-scroll
Ngx Ui Scroll
Infinite/virtual scroll for Angular
Stars: ✭ 145 (+866.67%)
Mutual labels:  infinite-scroll
Mypaint
MyPaint is a simple drawing and painting program that works well with Wacom-style graphics tablets.
Stars: ✭ 2,072 (+13713.33%)
Mutual labels:  infinite-scroll
Ng In Viewport
Allows us to check if an element is within the browsers visual viewport
Stars: ✭ 178 (+1086.67%)
Mutual labels:  infinite-scroll
Vue Quick Loadmore
A pull-down refresh and pull-up infinite scroll component for Vue.js.--vue移动端下拉刷新上拉无限滚动加载插件,支持更换加载图片,保存和设置滚动距离等。
Stars: ✭ 129 (+760%)
Mutual labels:  infinite-scroll
movie-app
🌈 TMDB + Laravel + LiveWire + AlpineJS + ViewModels + Components = ❤️ Movies App 🔥
Stars: ✭ 43 (+186.67%)
Mutual labels:  infinite-scroll
Infinitescrolling
Add infinite scrolling to collection view.
Stars: ✭ 156 (+940%)
Mutual labels:  infinite-scroll
Masonic
🧱 High-performance masonry layouts for React
Stars: ✭ 209 (+1293.33%)
Mutual labels:  infinite-scroll
Vue Scroller
Scroller Component for Vue.js
Stars: ✭ 1,775 (+11733.33%)
Mutual labels:  infinite-scroll
React Infinite Scroll Hook
A simple hook to create infinite scroll list components
Stars: ✭ 151 (+906.67%)
Mutual labels:  infinite-scroll
Infinitescroll
Infinite Scroll (Endless Scrolling) for RecyclerView in Android
Stars: ✭ 183 (+1120%)
Mutual labels:  infinite-scroll
Vertical Collection
Infinite Scroll and Occlusion at > 60FPS
Stars: ✭ 144 (+860%)
Mutual labels:  infinite-scroll
Vue Virtual Scroll List
⚡️A vue component support big amount data list with high render performance and efficient.
Stars: ✭ 3,201 (+21240%)
Mutual labels:  infinite-scroll
React Simple Infinite Scroll
A brutally simple react infinite scroll component
Stars: ✭ 132 (+780%)
Mutual labels:  infinite-scroll
Angular Search Experience
Algolia + Angular = 🔥🔥🔥
Stars: ✭ 167 (+1013.33%)
Mutual labels:  infinite-scroll
very good infinite list
A Very Good Infinite List Widget created by Very Good Ventures. Great for activity feeds, news feeds, and more. 🦄
Stars: ✭ 109 (+626.67%)
Mutual labels:  infinite-scroll
react-virtual-scroller
A react implementation of twitter VirtualScroller.
Stars: ✭ 43 (+186.67%)
Mutual labels:  infinite-scroll
Flutter sticky infinite list
Multi directional infinite list with Sticky headers for Flutter applications
Stars: ✭ 189 (+1160%)
Mutual labels:  infinite-scroll

react-use-infinite-loader ♾️ 📃

Netlify Status Run puppeteer tests on the example code npm version

Super lightweight infinite loading hook for React apps

react-use-infinite-loader uses the IntersectionObserver to provide a performant solution to infinite scrolling that doesn't involve scroll event listeners.

⚠️ Some older browsers may not support the IntersectionObserver API, however you can easily polyfill the functionality with this.

As the name suggests react-use-infinite-loader uses React Hooks, so you need to be using React function components to use this library.

Usage

See example/ for a full example (recommended), run it locally with yarn start. Also view it in the browser

Install with

yarn add react-use-infinite-loader

Add to your app

import useInfiniteLoader from 'react-use-infinite-loader';

Implement the hook. Ensure that the initial content page size flows off the page so that the next page isn't instantly fetched

const [canLoadMore, setCanLoadMore] = React.useState(true);
const [data, setData] = React.useState([]);
const loadMore = React.useCallback((page) => {
  loadFromAPI(page).then(response => {
    setCanLoadMore(response.canLoadMore);
    setData(currentData => [...currentData, ...response.data]);
  });
});
const { loaderRef } = useInfiniteLoader({ loadMore, canLoadMore });

Give the loaderRef that's returned from the hook to a div that sits directly below your rendered content list. Give it a classname that you'll use in the next step.

return (
  <>
    <h1>My App</h1>
    {items.map(item => <div>{item}</div>)}
    <div ref={loaderRef} className="loaderRef" />
  </>
);

Add the following CSS to your apps to allow the observer to see the div and know to load more data. Note that if you always have a DOM node with at least 1px height and width below the loaderRef div then you don't need to add this CSS. A common example where the CSS isn't required would be {canLoadMore && <div>Loading page {page + 1}</div>}.

/* You can change the name here and in your JSX if you want to */
.loaderRef {
  width: 1px;
  height: 1px;
  position: absolute;
}

API Reference

useInfiniteLoader arguments object

Property Default value Description
loadMore required Invoked when the user scrolls into the observable viewport + its rootMargin; read about rootMargin and thresholds here.
canLoadMore false Tells useInfiniteLoader whether to run loadMore when the observer is triggered, this is usually set dynamically.
rootMargin "100px 0px 0px 0px" Read about rootMargin here.
threshold 0 Read about threshold here.
initialise true Used for if your data fetching library fetches page 0 and renders it when the component loads, to use this just have a state flag that you set to false once the initial load from your data fetching lib has happened.
startFromPage 0 Used if you already load page 0 on mount, you can tell useInfiniteLoader what page to begin loading more from.
debug false Prints some helpful messages about what useInfiniteLoader is doing.

useInfiniteLoader result object

Property Description
loaderRef A React ref that you must pass to an element via ref={loaderRef}, this element must sit directly below your list of items that you're loading
page The current page that useInfiniteLoader has loaded
resetPage A function that resets the current page to startFromPage (default 0). This is useful if you change the context of the page but the component instance is the same
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].