1.0.52 • Published 4 years ago

react-scrollified v1.0.52

Weekly downloads
19
License
MIT
Repository
github
Last release
4 years ago

react-scrollified

Simple React infinite scroll component, utilizing IntersectionObserver

NPM JavaScript Style Guide

Demo

Install

npm install --save react-scrollified

API - ReactScrollified Props

OptiontypedefaultDescription
hasMoreboolean---got more to load?
loaderReactNode---element to use as loader
loadMorefunction---function used to load more items
offset?number0 (optional)starting offset
scrolledDiv?stringwindow (optional)the scrolled parent div id, !important - must have defined height. default is window

Usage Example

import * as React from 'react'
import styles from './styles.module.css'
import ReactScrollified from './infinite-scroll/infinite-scroll'
import { useEffect, useState } from 'react'

const loader = <span>Loading...</span>

const range = (start: number, stop: number, step = 1) =>
  Array(Math.ceil((stop - start) / step))
    .fill(start)
    .map((x, y) => x + y * step)

export const ExampleComponent = () => {
  const [items, setItems] = useState<any>([])
  useEffect(() => {
    loadMore(0)
  }, [])

  const loadMore = (offset: number) => {
    //your http request here
    const newData = range(offset, offset + 100)
    setTimeout(() => {
      setItems([...items, ...newData])
    }, 400)
  }

  return (
    <div id="scrolled-div" style={{ height: '800px' }}>
      <ReactScrollified
        scrolledDiv="scrolled-div"
        hasMore={true}
        loader={loader}
        loadMore={(offset) => loadMore(offset)}
      >
        {items.map((item: any, index: any) => (
          <div key={index}>{item}</div>
        ))}
      </ReactScrollified>
    </div>
  )
}

License

MIT © iscotzan

1.0.52

4 years ago

1.0.51

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.31

4 years ago

1.0.25

4 years ago

1.0.24

4 years ago

1.0.22

4 years ago

1.0.23

4 years ago

1.0.21

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago