1.2.3 • Published 4 years ago

@m-dary-nur/react-virtual-list v1.2.3

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

react-virtual-list

lightweight and flexible React Virtualized-listist Component Wrapper (support for React v16.8 ~ v16.13.1).

react-virtual-list help you virtualizing list for better performance and memory.

Benefits:

  • Zero dependency (no dependencies needed)
  • Very small library 1.8kB minified + gzipped !
  • Keep your components as a higher-order component
  • Very flexible - react-virtual-list just wrapped your map components and it will helps your component manage virtualizing your map list.

Installation

use yarn:

> yarn add @m-dary-nur/react-virtual-list

or use npm:

> npm install @m-dary-nur/react-virtual-list --save

Usage

The react-virtual-list module only exports a single file.

import VListWrapper from "@m-dary-nur/react-virtual-list";

Your inner component uses the react-virtual-list props to render the visible items and set a class and style to set the overall list.

const bigList = [{id: 1, name: "andi"}, {id: 2, name: "budi"}, ...., {id:99999, name: "zibi"}];

<VListWrapper 
  width="100%" // or width={100} (optional / not required)
  height="100%" // or height={500} (optional / not required) 
  items={bigList} // (required)
  itemHeight={40} // default itemHeight={50} (optional / not required) 
  itemBuffer={5} // default itemBuffer={2} (optional / not required) 
>
  {({ indexStart, items, itemStyle }) => (
    <table>
      <thead>
        <tr>
          <th>#</th>
          <th>name</th>
        </tr>
      <thead>
      <tbody>
        {items.map((item, index) => (
          <tr key={item.id}>
            <td>{indexStart + index + 1}</td> // its important for get numbering each item row
            <td style={itemStyle}>{item.name}</td> // add itemStyle on item row to set height offset (required)
          <tr>
        ))}
      </tbody>
    <table>
  )}
</VListWrapper>

Note: You should set itemStyle props for each item its require for virtualization.

that's it ! so simple.

VListWrapper properties

properties are used for setup react-virtual-list.

NameTypeDefaultDescription
itemsArray-Array of your list items.
itemHeightNumber50(optional) Height in pixels for each row item. if not set it will set as 50 pixel height as default.
itemBufferNumber2() Number of row that should be rendered before and after the visible view.
heightNumber / String'100%'Number / string for set height of VListWrapper
widthNumber / String'100%'Number / string for set width of VListWrapper

Example Usage

Coming soon but will be here

give a star :star2: if the library help you. :relaxed:

1.2.3

4 years ago

1.2.2

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.2

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago