1.0.0 • Published 4 months ago

react-lazy-grid v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

react-lazy-grid

react-lazy-grid is a React component that dynamically renders only the visible portion of a grid based on the scroll position. It is used to efficiently display large grids.

Installation

npm install react-lazy-grid

or

yarn add react-lazy-grid

Usage

import React from "react";
import LazyGrid from "react-lazy-grid";

const MyComponent = (props) => {
  return <div>{props.content}</div>;
};

const App = () => {
  const grid = [
    [{ content: "Item 1" }, { content: "Item 2" }],
    [{ content: "Item 3" }, { content: "Item 4" }],
  ];

  return (
    <LazyGrid
      grid={grid}
      Component={MyComponent}
      width="500px"
      height="500px"
      itemWidth={100}
      itemHeight={100}
      transpose={false}
    />
  );
};

export default App;

Props

LazyGridProps

NameTypeDescription
gridany[][] | any[]A 2D or 1D array where each element is a property object passed to the component.
ComponentReact.FC<any>The component displayed in each grid cell.
widthstringThe width of the entire grid.
heightstringThe height of the entire grid.
itemWidthnumberThe width of each grid cell.
itemHeightnumberThe height of each grid cell.
buffernumberOptional. The number of extra rows and columns to render outside the visible area.
transposebooleanOptional. If true, transposes the grid (switches rows and columns).

License

MIT

1.0.0

4 months ago