react-infinity-scroll
Small React component for implementing infinity scroll
Demo
I've created a demo with create-react-app
so you can see my component in action. The source can be found in gh-pages
branch, don't judge me, please, I was in a hurry.
Demo: https://khorolets.github.io/react-infinity-scroll/
Installation
$ npm install react-infinity-scroll --save
Usage
Component { superprops thisstate = 'reviews': 'hasMore': false } { } { } { return <InfinityScroll pageStart=1 bottomOffset=250 loadMore=thisloadMore hasMore=thisstatehasMore loader=<div className="loader">Loading ...</div> > thisstatereviews </InfinityScroll> }
InfinityScroll
inside other elements (e.g. modals)
Using If you need to use InfinityScroll
in modal or other div which is scrollable you need to listen that scroll instead of default window
one.
InfinityScroll
won't add listeners to window
if you provide bottomOffsetValue
which is representing current distance to the bottom of the element.
So you need manually to:
- Add listener to an element that has a scroll you're interested in.
{ document0 } { document0 }
- Create a method that calculates current offset
{ const modalWrapper = document0 const modalBody = document0 return this }
- Pass that method to
InfinityScroll
<InfinityScroll pageStart=1 bottomOffset=1000 bottomOffsetValue=thisstatebottomOffsetValue loadMore=thispropsloadMore hasMore=thispropshasMore loader=<div className="text-center loader">Loading...</div>>...</InfinityScroll>
That's it.
You may also be interested
- React 8 (infinity) https://www.npmjs.com/package/react-8
- react-infinity-scroller https://www.npmjs.com/package/react-infinity-scroller