0.0.6 • Published 3 years ago

react-infinite-virtual-scroll v0.0.6

Weekly downloads
17
License
-
Repository
github
Last release
3 years ago

React Infinite Virtual Scroll

demo: github page

Why

There are already many virtualize list libraries out there, but I can't find one that satisfies all these, so I decided to create one myself.

  • Simple: no dependencies other than react
  • Allow dynamic row height
    • But the viewport height must be fixed.
    • Set the viewport height by passing style prop.
  • Utilizing async iterable feature which is awesome.
  • High Performance

How

Important: You Must set a fixed height via style prop for it to work!

import InfiniteVirtualScroll from "react-infinite-virtual-scroll"

function Foo(){
    const [searchText,setSearchText] = useState("")
    const dataSource = useMemo(()=>async function *GetData(){
        let total = Infinity
        let page = 0
        let pageSize = 20
        while(page * pageSize < total){
            const {data,total:remoteTotal} = await fetch("/data",{
                method:"post",
                body:JSON.stringify({
                    page,
                    pageSize:pageSize
                })
            })
            page = page + 1
            total = remoteTotal
            yield data
        }
    },[searchText])

    return <div>
        <InfiniteVirtualScroll dataSource={dataSource} style={{height:"200vh" /** Height Must Not Be "auto" For It To Work */  }}>  
            {(rows)=>{
                return rows.map(row=><div key={row.id}>
                    <ItemDisplayComponent item={item} />
                </div>)
            }}
        </InfiniteVirtualScroll>
    </div>
}

License

Anti996

0.0.6

3 years ago

0.0.3

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago