Member-only story
Create Auto-Resizeable Lists and Grid with the react-virtualized Library
3 min readFeb 20, 2021
The react-virtualized package lets us display a virtualized list.
We can use it with the AutoSizer
component to create a virtualized list that resizes the item.
In this article, we’ll look at how to create automatically resizeable lists and grids with the react-virtualized library.
Installation
To install it, we run:
npm i react-virtualized
AutoSizer
We can use the AutoSizer
component to add the auto-resizable list.
For example, we can write:
import React from "react";
import { AutoSizer, List } from "react-virtualized";
import "react-virtualized/styles.css";const list = Array(1000)
.fill(0)
.map((_, i) => i);function rowRenderer({ key, index, style }) {
return (
<div key={key} style={style}>
{list[index]}
</div>
);
}export default function App() {
return (
<div style={{ height: "100vh" }}>
<AutoSizer>
{({ height, width }) => (
<List
height={height}
rowCount={list.length}
rowHeight={20}
rowRenderer={rowRenderer}…