0.0.6 • Published 4 years ago

react-infscroll-lazyload v0.0.6

Weekly downloads
78
License
-
Repository
-
Last release
4 years ago

The react-infscroll-lazyload package is a component library for React, where you can easy configurate it and pass an Item component and a request to get a list with infinite scroll and lazy loading Items.

Getting started

npm install react-infscroll-lazyload

Example

import InfiniteScrollWithLazyLoad from 'react-infscroll-lazyload';
import ListItem from './components/listItem'
import Loader from './components/loader'

  const MyComponent = () => {      
    const request = async (pages) => {  
    try {
      const response = await fetch(`https://URL&page=${pages}`);
      return await response.json();
    } catch (error) {
      console.error(error);
      return false;
    }
  }
  
  return (
    <InfiniteScrollWithLazyLoad 
      Loader= {Loader}
      itemHeight = {'300px'}
      itemWidth = {'15vw'}
      iSrootVal = {null}
      iSrootMargin = '0px'
      iSthreshold = {1}
      lazyRootVal = {null}
      lazyRootMargin = '0px'
      lazyThreshold = {0.1}
      Children={Children}
      request={request}
      transformer= {(res) => res.results.map((element) => ({
          small: element.urls.thumb,
          description: element.alt_description
        })
      )}
    />
  )
}

Props

Prop nameTypeDefaultRequiredDescription
LoaderComponentDefault LoaderfalseCustom loader component
itemHeigthString'100%'falseDefined height for the Item and the placeholder
itemWidthString'100vw'falseDefined weight for the Item and the placeholde
ISrootValDOM ElementnullfalseThe element that is used as the viewport for the infinite scroll. Must be the ancestor of the infiniteScrollWithLazyLoad component . Defaults to the browser viewport if not specified.
iSrootMarginString'0px'falseMargin around the root, This set of values serves to grow or shrink each side of the root element's bounding box before updating the list.
iSthresholdNumber1.0falseEither a single number or an array of numbers which indicate at what percentage of the target's visibility the infinite scroll should add the next request.
lazyRootValDOM ElementnullfalseThe element that is used as the viewport for the Item. Must be the ancestor of the Item component. Defaults to the browser viewport if not specified.
lazyRootMarginString'0px'falseMargin around the root, This set of values serves to grow or shrink each side of the root element's bounding box before updating the list.
lazyThresholdNumber0.2falseEither a single number or an array of numbers which indicate at what percentage of the target's visibility the infinite scroll should add the next request.
ChildrenComponentnulltrueYour List Item component
requestFunctionnulltrueYour fetching handler function, get the page number as argument
transformerFunctionnulltrueFunction to transform the data for mapping it

Contributors

0.0.5

4 years ago

0.0.6

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

0.0.1

4 years ago

0.0.2

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

0.1.0

4 years ago