2.0.0 • Published 3 years ago

react-mini-virtrual-list v2.0.0

Weekly downloads
3
License
MIT
Repository
github
Last release
3 years ago

react-mini-virtrual-list

English | 中文说明

Version

Whath is virtrual list And how to use?

Used when loading a large amount of data at once, the theory is to calculate the index items to render based on the set size before rendering the data, and then render the list in the visual area, outside of which it will not be rendered.

why choose it

If you're looking for a component that simply renders list data, this might be a good choice, as it provides an easy and convenient API and flexible control over the rendering of lists.

  • supports rendering within visual areas, while rendering outside visual areas will be unloaded
  • supports custom rendering dataSources
  • supports lists of horizontal and vertical scrolling directions
  • Custom preload margin and load location or index

install

npm install --save react-mini-virtrual-list
# or
yarn add react-mini-virtrual-list

example

import VirtrualList from 'react-mini-virtrual-list';

// for example
const Home = () => {

    const [dataSource, setDataSource] = useState([...new Array(100).keys()]);

    const renderOn = (startIndex, stopIndex) => {
        // console.log(startIndex, stopIndex);
    };

    const renderItem = (item: any, index: number) => {
      return (
        <div className="Row" key={index}>
            Row #{item}
        </div>
      );
    };
    
    return (
        <>
            <VirtrualList
                width="auto"
                // scrollToAlignment="start"
                // scrollToIndex={30}
                scrollOffset={500}
                height={400}
                limit={200}
                dataSource={dataSource}
                renderItem={renderItem}
                onItemsRendered={renderOn}
                itemSize={50}
                className="VirtualList"
            />
        </>
    );
}

属性说明

nametypedefaultValuedescription
estimatedItemSizenumber50Estimated size of list elements (scroll direction)
width和heightnumber / string-The size of the visual area of the list (scroll direction)
limitnumber-Maximum number of lazy loads
itemSizenumber / array / function-Height (width) of list elements
onScrollfunction-Scroll triggered function
onItemsRenderedfunction-The function that is triggered when new data is loaded, stopIndex is the start and end indexes of the render
overscanCountnumber3Number of pre-loaded elements (three before and three after default)
renderItemfunction-Returns the rendered unit
dataSourceArray-Customize the data source for rendering
scrollOffsetnumber-Sets which location to scroll to
scrollToIndexnumber-To set which data to scroll to, choose between scrollOffset
scrollToAlignmentstringstart / center / end / autoIn combination with 'scrollToIndex', specify the location of the index entry in the visible area 'start' starting area 'center' middle area 'end' tail area 'auto' automatically displays the location of 'scrollToIndex'
scrollDirectionstringvertical / horizontalSets the scrolling direction of the list. Default is' vertical '

Contribute

Thanks to the inspiration from React -virtualized and React -tiny- Virtrual list, you can go to support if you want to have more and more complex features!