1.1.0 • Published 3 years ago

react-box-virtualization v1.1.0

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

react-box-virtualization

React component for the optimized rendering of large datasets by custom positioning and virtualization.

React box virtualizer works by only rendering part of a large datasets.

  1. It reduces the memory footprint by avoiding the over-allocation of DOM nodes.
  2. It reduces the CPU load by avoiding, calculating positions, and rendering all boxes immediately.

Below you can find a small diagram which is reflected the impact of react box virtualization. Only boxes whose coordinates in the viewport are will be rendered.

NPM registry License

react-box-virtualization-1

Install

# Yarn
yarn add react-box-virtualization

# NPM
npm install --save react-box-virtualization

Usage

  1. Import box virtualizer component
import { BoxVirtualizer } from 'react-box-virtualization';
  1. Create a variable which is responsible for mapping properties from your object to box props
const coordinatesMap = {
    x: 'xVal',
    y: 'yVal',
    width: 'widthVal',
    height: 'heightVal'
};

Here is the interface of typescript for this prop

interface ICoordinatesMap {
    x: string;
    y: string;
    width: string;
    height: string;
    opacity?: string;
    isVisible?: boolean;
    zIndex?: number;
}
  1. Add BoxVirtualizer component to your JSX code
<BoxVirtualizer
    coordinatesMap={coordinatesMap}
    data={dataset}
    isVirtualized={true}
    boxGap={20}
    visualizableContent={VisualizableContent}
/>

Supported props of BoxVirtualizer component

Prop nameDescriptionTypeDefault valueRequired
dataArray of objectsany[]-yes
coordinatesMapMap object for mapping data item property to CSS visual propertyICoordinatesMap-yes
visualizableContentReact component which will receive data item object as propsReact.FC-yes
isVirtualizedIn case of false value, rendering of boxes will work with a lazy render concept which means each box will be rendered one timebooleantrueno
viewportHeightHeight of viewport can be all CSS acceptable units for the height propertystring'100%'no
viewportWidthWidth of viewport can be all CSS acceptable units for the width propertystring'100%'no
boxGapGap between boxes can be all CSS acceptable units for the padding propertynumber0no

Demos

Here's a boxes with random positions and sizes Code Sandbox demo rendered by lazy render concept. (Dataset size 1.000.000 boxes) Here's a boxes with grid layout Code Sandbox demo rendered by virtualization concept. (Dataset size 100.000 boxes)

License

MIT Licensed © 2022 Hamik25

1.0.2

3 years ago

1.1.0

3 years ago

1.0.1

3 years ago

0.0.8

3 years ago

0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.2

3 years ago

0.0.1

3 years ago

1.0.0

3 years ago