0.0.5-ALPHA • Published 4 years ago

@mierak/react-virtualized-grid v0.0.5-ALPHA

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

React Virtualized Grid

A simple layout component written using CSS Grid. Can be used to display a very large number of elements in a grid. This works by rendering only elements that are currently on the screen and a small portion before and after.

Features

  • A Simple CSS Grid to display a huge number of elements
  • Almost identical performance for 10, 100 or 1 000 000 elements
  • Responsive
  • Zero dependency
  • Written in Typescript

Installation

npm i @mierak/react-virtualized-grid

Usage

import React from 'react';
import { VirtualizedGrid } from '@mierak/react-virtualized-grid';

export default () => {
	const elements = [...new Array(100000)].map((_, index) => index);

	return (
		<VirtualizedGrid itemCount={elements.length} rowHeight={50} cellWidth={100} gridHeight={300}>
			{(index) => <div>{elements[index]}</div>}
		</VirtualizedGrid>
	);
};

Preview

Preview

API

NameDescriptionTypeDefaultRequired?
childrenA callback function used to render your elements(index: number, rowIndex: number, columnIndex: number) => React.ReactNode---Yes
itemCountTotal count of items you want to displaynumber---Yes
rowHeightHeight of a single row in the gridnumber---Yes
cellWidthWidth of a single cell in the gridnumber---Yes
debounceDelayTime to wait before rendering elements after a scroll event in millisecondsnumber300No
prerenderScreensScreens of elements to prerender to prevent blinkingnumber3No
gridGapgrid-gap CSS propertynumber0No
gridHeightThe height of the grid container. You can supply a number in px or a string as a CSS property, e.g. "calc(100% - 200px)"number | string"100vh"No
classNameYour css class names to be added to grid container. Also servers for Styled components compatibilitynumber---No

Notes

You can use any of the parameters passed in the children callback to render your elements. Suggested way is to simply use an index. If you use rowIndex and columnIndex you must take care not to skip any cells in the resulting grid as it will cause it to malfunction.

Limitations

  • All elements must have equal size
  • Currently there is no inbuilt way to render previews before element gets rendered after scrolling

Licence

React Virtualized Grid is release under MIT licence.