Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-window

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-window

React components for efficiently rendering large, scrollable lists and tabular data

  • 1.8.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6M
decreased by-17.41%
Maintainers
2
Weekly downloads
 
Created

What is react-window?

The react-window npm package is a React component library that provides efficient rendering of large lists and tabular data. It works by only rendering the items that are currently visible within the viewport, which can significantly improve the performance of applications that need to display large amounts of data.

What are react-window's main functionalities?

Fixed Size List

This feature allows you to render a list where each item has a fixed size. The FixedSizeList component requires you to specify the height and width of the list container, the number of items, and the size of each item.

import { FixedSizeList } from 'react-window';

function App() {
  return (
    <FixedSizeList
      height={150}
      itemCount={1000}
      itemSize={35}
      width={300}
    >
      {({ index, style }) => <div style={style}>Row {index}</div>}
    </FixedSizeList>
  );
}

Variable Size List

This feature is similar to the FixedSizeList but allows for items with variable sizes. The VariableSizeList component requires an itemSize function that returns the size of an item given its index.

import { VariableSizeList } from 'react-window';

const rowHeights = new Array(1000).fill(true).map(() => 25 + Math.round(Math.random() * 50));

function App() {
  return (
    <VariableSizeList
      height={150}
      itemCount={1000}
      itemSize={index => rowHeights[index]}
      width={300}
    >
      {({ index, style }) => <div style={style}>Row {index}</div>}
    </VariableSizeList>
  );
}

Fixed Size Grid

The FixedSizeGrid component allows you to render a grid (or table) where each cell has a fixed size. You need to specify the dimensions of the grid, the size of each cell, and the number of rows and columns.

import { FixedSizeGrid } from 'react-window';

function App() {
  return (
    <FixedSizeGrid
      columnCount={100}
      columnWidth={100}
      height={150}
      rowCount={1000}
      rowHeight={35}
      width={300}
    >
      {({ columnIndex, rowIndex, style }) => <div style={style}>Cell {rowIndex},{columnIndex}</div>}
    </FixedSizeGrid>
  );
}

Variable Size Grid

The VariableSizeGrid component is used for rendering a grid where the size of cells can vary. It requires functions to determine the height of rows and the width of columns based on their indices.

import { VariableSizeGrid } from 'react-window';

const columnWidths = new Array(100).fill(true).map(() => 75 + Math.round(Math.random() * 50));
const rowHeights = new Array(1000).fill(true).map(() => 25 + Math.round(Math.random() * 50));

function App() {
  return (
    <VariableSizeGrid
      columnCount={100}
      columnWidth={index => columnWidths[index]}
      height={150}
      rowCount={1000}
      rowHeight={index => rowHeights[index]}
      width={300}
    >
      {({ columnIndex, rowIndex, style }) => <div style={style}>Cell {rowIndex},{columnIndex}</div>}
    </VariableSizeGrid>
  );
}

Other packages similar to react-window

Keywords

FAQs

Package last updated on 12 Apr 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc