react-window vs react-virtualized vs react-list vs react-tiny-virtual-list vs react-infinite
Listes Virtuelles et Infinites en React
react-windowreact-virtualizedreact-listreact-tiny-virtual-listreact-infinitePacchetti simili:

Listes Virtuelles et Infinites en React

Les bibliothèques de listes virtuelles et infinies en React sont conçues pour gérer efficacement l'affichage de grandes quantités de données dans des composants de liste. Elles utilisent des techniques telles que le défilement infini, la virtualisation et le rendu paresseux pour n'afficher qu'un sous-ensemble d'éléments à la fois, réduisant ainsi l'utilisation de la mémoire et améliorant les performances. Ces bibliothèques sont particulièrement utiles pour les applications qui doivent afficher des listes longues sans compromettre la réactivité ou la fluidité de l'interface utilisateur. react-infinite est une bibliothèque pour le défilement infini qui charge dynamiquement des éléments supplémentaires au fur et à mesure que l'utilisateur fait défiler la liste. react-list fournit un rendu efficace des listes en utilisant la virtualisation pour n'afficher que les éléments visibles. react-tiny-virtual-list est une solution légère pour la virtualisation des listes, offrant un bon équilibre entre taille et performance. react-virtualized est une bibliothèque complète qui propose des composants hautement personnalisables pour la virtualisation des listes, des tableaux et des grilles. react-window est une version plus légère de react-virtualized, conçue pour être simple à utiliser tout en offrant des performances élevées pour la virtualisation des listes et des grilles.

Trend di download npm

3 Anni

Classifica GitHub Stars

Dettaglio statistiche

Pacchetto
Download
Stars
Dimensione
Issues
Pubblicazione
Licenza
react-window8,481,69417,212428 kB1il y a 5 joursMIT
react-virtualized2,262,03727,0671.31 MB1il y a 19 joursMIT
react-list651,5131,97035.3 kB72il y a 4 moisMIT
react-tiny-virtual-list140,3272,483-55il y a 8 ansMIT
react-infinite10,1032,682243 kB101-BSD-3-Clause

Confronto funzionalità: react-window vs react-virtualized vs react-list vs react-tiny-virtual-list vs react-infinite

Type de Virtualisation

  • react-window:

    react-window se concentre sur la virtualisation des listes et des grilles avec une approche simple et efficace. Elle rend uniquement un sous-ensemble d'éléments à la fois, ce qui réduit le temps de rendu et l'utilisation de la mémoire.

  • react-virtualized:

    react-virtualized propose plusieurs techniques de virtualisation, y compris la virtualisation des listes, des tableaux et des grilles. Elle offre une flexibilité maximale et permet aux développeurs de choisir la méthode de virtualisation qui convient le mieux à leur cas d'utilisation.

  • react-list:

    react-list utilise la virtualisation pour n'afficher que les éléments visibles dans la liste, réduisant ainsi le nombre d'éléments rendus à tout moment. Cela améliore les performances, en particulier pour les longues listes.

  • react-tiny-virtual-list:

    react-tiny-virtual-list utilise également la virtualisation, mais se concentre sur une approche légère et efficace. Elle rend uniquement les éléments visibles en fonction de la position de défilement, ce qui réduit l'utilisation de la mémoire.

  • react-infinite:

    react-infinite utilise le défilement infini, ce qui signifie qu'il charge dynamiquement plus d'éléments au fur et à mesure que l'utilisateur fait défiler vers le bas. Cela nécessite une API qui prend en charge le chargement de données par lots.

Taille de la Bibliothèque

  • react-window:

    react-window est une bibliothèque légère par rapport à react-virtualized, offrant une bonne balance entre taille et fonctionnalités, ce qui la rend adaptée aux projets modernes.

  • react-virtualized:

    react-virtualized est plus grande en raison de sa richesse fonctionnelle et de ses nombreux composants, mais elle justifie son poids par les fonctionnalités avancées qu'elle offre.

  • react-list:

    react-list est une bibliothèque légère qui n'ajoute pas beaucoup de poids à votre application, ce qui en fait un bon choix pour les projets sensibles à la taille.

  • react-tiny-virtual-list:

    react-tiny-virtual-list est conçue pour être ultra-légère, ce qui la rend idéale pour les applications où chaque kilo-octet compte.

  • react-infinite:

    react-infinite est relativement légère, mais sa taille dépend de la façon dont elle est utilisée et des dépendances qu'elle nécessite pour le chargement infini.

Facilité d'Utilisation

  • react-window:

    react-window est conçue pour être simple et intuitive, avec une API qui facilite la virtualisation des listes et des grilles sans configuration complexe.

  • react-virtualized:

    react-virtualized peut avoir une courbe d'apprentissage en raison de sa complexité et de la richesse de ses fonctionnalités. Cependant, la documentation est exhaustive et fournit de nombreux exemples.

  • react-list:

    react-list offre une API simple et intuitive pour le rendu des listes. Sa simplicité en fait un bon choix pour les développeurs qui veulent une solution rapide sans trop de configuration.

  • react-tiny-virtual-list:

    react-tiny-virtual-list est très facile à utiliser, avec une API minimaliste qui permet une intégration rapide dans les projets. La documentation est concise et utile.

  • react-infinite:

    react-infinite est assez simple à mettre en œuvre, surtout si vous avez déjà une API qui prend en charge le chargement de données par lots. La documentation est claire et fournit des exemples.

Exemple de Code

  • react-window:

    Exemple de liste virtualisée avec react-window

    import React from 'react';
    import { FixedSizeList } from 'react-window';
    
    const WindowedList = () => {
      const items = Array.from({ length: 1000 }, (_, i) => `Item ${i + 1}`);
    
      return (
        <FixedSizeList
          height={400}
          itemCount={items.length}
          itemSize={35}
          width={300}
        >
          {({ index, style }) => (
            <div style={{ ...style, border: '1px solid #ccc', margin: '2px 0' }}>
              {items[index]}
            </div>
          )}
        </FixedSizeList>
      );
    };
    
    export default WindowedList;
    
  • react-virtualized:

    Exemple de liste virtualisée avec react-virtualized

    import React from 'react';
    import { List } from 'react-virtualized';
    
    const VirtualizedList = () => {
      const items = Array.from({ length: 1000 }, (_, i) => `Item ${i + 1}`);
    
      return (
        <List
          width={300}
          height={400}
          rowCount={items.length}
          rowHeight={30}
          rowRenderer={({ index, key, style }) => (
            <div key={key} style={{ ...style, border: '1px solid #ccc', margin: '2px 0' }}>
              {items[index]}
            </div>
          )}
        />
      );
    };
    
    export default VirtualizedList;
    
  • react-list:

    Exemple de liste virtuelle avec react-list

    import React from 'react';
    import { List } from 'react-list';
    
    const VirtualList = () => {
      const items = Array.from({ length: 1000 }, (_, i) => `Item ${i + 1}`);
    
      return (
        <List
          itemRenderer={(index, key) => (
            <div key={key} style={{ height: 30, border: '1px solid #ccc', margin: '5px 0' }}>
              {items[index]}
            </div>
          )}
          length={items.length}
          type="uniform"
        />
      );
    };
    
    export default VirtualList;
    
  • react-tiny-virtual-list:

    Exemple de virtualisation légère avec react-tiny-virtual-list

    import React from 'react';
    import { VirtualList } from 'react-tiny-virtual-list';
    
    const TinyVirtualList = () => {
      const items = Array.from({ length: 500 }, (_, i) => `Item ${i + 1}`);
    
      return (
        <VirtualList
          width={300}
          height={400}
          itemCount={items.length}
          itemSize={35}
          overscanCount={5}
          itemRenderer={(index) => (
            <div style={{ height: 35, border: '1px solid #ccc', margin: '2px 0' }}>
              {items[index]}
            </div>
          )}
        />
      );
    };
    
    export default TinyVirtualList;
    
  • react-infinite:

    Exemple de défilement infini avec react-infinite

    import React, { useState } from 'react';
    import Infinite from 'react-infinite';
    
    const InfiniteList = () => {
      const [items, setItems] = useState(Array.from({ length: 20 }, (_, i) => `Item ${i + 1}`));
    
      const loadMoreItems = () => {
        const newItems = Array.from({ length: 20 }, (_, i) => `Item ${items.length + i + 1}`);
        setItems((prevItems) => [...prevItems, ...newItems]);
      };
    
      return (
        <Infinite
          elementHeight={50}
          infiniteLoadBeginEdge={100}
          infiniteLoadBeginBottomOffset={200}
          onInfiniteLoad={loadMoreItems}
          isInfiniteLoading={false}
        >
          {items.map((item) => (
            <div key={item} style={{ height: 50, border: '1px solid #ccc', margin: '5px 0' }}>
              {item}
            </div>
          ))}
        </Infinite>
      );
    };
    
    export default InfiniteList;
    

Come scegliere: react-window vs react-virtualized vs react-list vs react-tiny-virtual-list vs react-infinite

  • react-window:

    Choisissez react-window si vous recherchez une bibliothèque de virtualisation légère et facile à utiliser qui offre d'excellentes performances. Elle est idéale pour les projets qui ont besoin de virtualisation sans la surcharge des fonctionnalités supplémentaires.

  • react-virtualized:

    Utilisez react-virtualized si vous avez besoin de fonctionnalités avancées et de composants hautement personnalisables pour la virtualisation des listes, des tableaux et des grilles. Elle est adaptée aux applications complexes qui nécessitent un contrôle fin sur le rendu des éléments.

  • react-list:

    Optez pour react-list si vous souhaitez une bibliothèque légère qui utilise la virtualisation pour améliorer les performances des listes sans trop de complexité. Elle convient aux listes où tous les éléments sont déjà chargés, mais vous voulez réduire le rendu à ceux qui sont visibles.

  • react-tiny-virtual-list:

    Sélectionnez react-tiny-virtual-list si vous avez besoin d'une solution minimaliste pour la virtualisation des listes avec une empreinte mémoire réduite. Elle est parfaite pour les applications où la taille du paquet et les performances sont des préoccupations majeures.

  • react-infinite:

    Choisissez react-infinite si vous avez besoin d'une solution simple pour le défilement infini avec chargement dynamique des données. Elle est idéale pour les listes où les éléments sont chargés par lots au fur et à mesure que l'utilisateur fait défiler.

README per react-window

react-window logo

react-window is a component library that helps render large lists of data quickly and without the performance problems that often go along with rendering a lot of data. It's used in a lot of places, from React DevTools to the Replay browser.

Support

If you like this project there are several ways to support it:

The following wonderful companies and individuals have sponsored react-window:

Installation

Begin by installing the library from NPM:

npm install react-window

TypeScript types

TypeScript definitions are included within the published dist folder

FAQs

Frequently asked questions can be found here.

Documentation

Documentation for this project is available at react-window.vercel.app.

List

Renders data with many rows.

Required props

NameDescription
rowComponent

React component responsible for rendering a row.

This component will receive an index and style prop by default. Additionally it will receive prop values passed to rowProps.

ℹ️ Spread ariaAttributes onto the row element; they identify it as a row (e.g. so that dynamic row heights are measured reliably)

ℹ️ The prop types for this component are exported as RowComponentProps

rowCount

Number of items to be rendered in the list.

rowHeight

Row height; the following formats are supported:

  • number of pixels (number)
  • percentage of the list's current height (string)
  • function that returns the row height (in pixels) given an index and rowProps
  • dynamic row height cache returned by the useDynamicRowHeight hook

ℹ️ Percentage heights can't be resolved during server rendering unless a defaultHeight (or a pixel height via the style prop) is specified.

⚠️ Dynamic row heights are not as efficient as predetermined sizes. It's recommended to provide your own height values if they can be determined ahead of time.

rowProps

Additional props to be passed to the row-rendering component. List will automatically re-render rows when values in this object change.

⚠️ This object must not contain ariaAttributes, index, or style props.

Optional props

NameDescription
className

CSS class name.

style

Optional CSS properties. The list of rows will fill the height defined by this style.

children

Additional content to be rendered within the list (above rows). This property can be used to render things like overlays or tooltips.

defaultHeight

Default height of list (in pixels) for initial render, before its actual height has been measured.

ℹ️ Lists can't be measured during server rendering, so this value determines how many rows are server rendered. It's recommended to set this to the expected height of the list (or to specify a pixel height via the style prop).

defaultScrollOffset

Initial scroll offset (in pixels) of the list. This value is only applied once, when the list first mounts with at least one row.

ℹ️ Server-rendered HTML can't be pre-scrolled, so server rendering always starts at the first row; the default scroll offset is applied once the list hydrates.

⚠️ If the list can't be scrolled that far when the offset is applied (e.g. it is hidden with display: none, or uses percentage row heights before its height has been measured), the offset is clamped or ignored and not retried. Specify a defaultHeight (or a pixel height via the style prop) when using percentage row heights.

listRef

Ref used to interact with this component's imperative API.

This API has imperative methods for scrolling and a getter for the outermost DOM element.

ℹ️ The useListRef and useListCallbackRef hooks are exported for convenience in TypeScript projects.

onResize

Callback notified when the List's outermost HTMLElement resizes. This may be used to (re)scroll a row into view.

onRowsRendered

Callback notified when the range of visible rows changes.

overscanCount

How many additional rows to render outside of the visible area. This can reduce visual flickering near the edges of a list when scrolling.

rowKey

Lists use the row index as a key by default. This prop can provide a custom key value.

ℹ️ Custom keys can ensure better UX for sortable or filterable lists, particularly if your row components are stateful. Refer to the React documentation for more info.

⚠️ This prop cannot be auto-memoized because it is called during render. It is important to always useCallback for this prop; do not use an inline function.

scrollElement

Element that scrolls the list, for lists that scroll along with other content (e.g. the page):

  • "window" to scroll with the page
  • an ancestor element that scrolls (e.g. stored with a useState ref callback); null until it has mounted

The list renders at its full height and only renders the rows visible within the scroll element's viewport. Its position within the scroll element is measured whenever it renders, scrolls, or resizes, and whenever content before it is resized, inserted, or removed (e.g. an image loading above the list).

  • scrollToRow scrolls the scroll element
  • defaultHeight is used as the viewport height until the scroll element has been measured (e.g. during server rendering)
  • percentage row heights are relative to the scroll element's viewport height
  • defaultScrollOffset is ignored

ℹ️ While the scroll element is null, the list renders the first rows (as it does during server rendering).

⚠️ The list itself doesn't scroll, so its onScroll handler isn't called; listen to the scroll element's "scroll" events instead (or use the useIsScrolling hook).

tagName

Can be used to override the root HTML element rendered by the List component. The default value is "div", meaning that List renders an HTMLDivElement as its root.

⚠️ In most use cases the default ARIA roles are sufficient and this prop is not needed.

Grid

Renders data with many rows and columns.

ℹ️ Unlike List rows, Grid cell sizes must be known ahead of time. Either static sizes or something that can be derived (from the data in CellProps) without rendering.

Required props

NameDescription
cellComponent

React component responsible for rendering a cell.

This component will receive columnIndex, rowIndex, and style props by default. Additionally it will receive prop values passed to cellProps.

ℹ️ The prop types for this component are exported as CellComponentProps

cellProps

Additional props to be passed to the cell-rendering component. Grid will automatically re-render cells when values in this object change.

⚠️ This object must not contain ariaAttributes, columnIndex, rowIndex, or style props.

columnCount

Number of columns to be rendered in the grid.

columnWidth

Column width; the following formats are supported:

  • number of pixels (number)
  • percentage of the grid's current width (string)
  • function that returns the column width (in pixels) given an index and cellProps

ℹ️ Percentage widths can't be resolved during server rendering unless a defaultWidth (or a pixel width via the style prop) is specified.

rowCount

Number of rows to be rendered in the grid.

rowHeight

Row height; the following formats are supported:

  • number of pixels (number)
  • percentage of the grid's current height (string)
  • function that returns the row height (in pixels) given an index and cellProps

ℹ️ Percentage heights can't be resolved during server rendering unless a defaultHeight (or a pixel height via the style prop) is specified.

Optional props

NameDescription
className

CSS class name.

dir

Indicates the directionality of grid cells.

ℹ️ The directionality of an ancestor element can't be detected during server rendering; specify this prop explicitly for server-rendered right-to-left grids.

ℹ️ See HTML dir global attribute for more information.

style

Optional CSS properties. The grid of cells will fill the height and width defined by this style.

children

Additional content to be rendered within the grid (above cells). This property can be used to render things like overlays or tooltips.

columnKey

Grids use the column index as a key by default. This prop can be used along with the rowKey prop to provide a custom key value.

ℹ️ Custom keys can ensure better UX for sortable or filterable grids, particularly if your cell components are stateful. Refer to the React documentation for more info.

⚠️ This prop cannot be auto-memoized because it is called during render. It is important to always useCallback for this prop; do not use an inline function.

defaultHeight

Default height of grid (in pixels) for initial render, before its actual height has been measured.

ℹ️ Grids can't be measured during server rendering, so this value determines how many rows are server rendered. It's recommended to set this to the expected height of the grid (or to specify a pixel height via the style prop).

defaultScrollLeft

Initial horizontal scroll offset (in pixels) of the grid. This value is only applied once, when the grid first mounts with at least one column.

ℹ️ Server-rendered HTML can't be pre-scrolled, so server rendering always starts at the first column; the default scroll offset is applied once the grid hydrates.

⚠️ If the grid can't be scrolled that far when the offset is applied (e.g. it is hidden with display: none, or uses percentage column widths before its width has been measured), the offset is clamped or ignored and not retried. Specify a defaultWidth (or a pixel width via the style prop) when using percentage column widths.

defaultScrollTop

Initial vertical scroll offset (in pixels) of the grid. This value is only applied once, when the grid first mounts with at least one row.

ℹ️ Server-rendered HTML can't be pre-scrolled, so server rendering always starts at the first row; the default scroll offset is applied once the grid hydrates.

⚠️ If the grid can't be scrolled that far when the offset is applied (e.g. it is hidden with display: none, or uses percentage row heights before its height has been measured), the offset is clamped or ignored and not retried. Specify a defaultHeight (or a pixel height via the style prop) when using percentage row heights.

defaultWidth

Default width of grid (in pixels) for initial render, before its actual width has been measured.

ℹ️ Grids can't be measured during server rendering, so this value determines how many columns are server rendered. It's recommended to set this to the expected width of the grid (or to specify a pixel width via the style prop).

gridRef

Imperative Grid API.

ℹ️ The useGridRef and useGridCallbackRef hooks are exported for convenience in TypeScript projects.

onCellsRendered

Callback notified when the range of rendered cells changes.

onResize

Callback notified when the Grid's outermost HTMLElement resizes. This may be used to (re)scroll a cell into view.

overscanCount

How many additional rows/columns to render outside of the visible area. This can reduce visual flickering near the edges of a grid when scrolling.

rowKey

Grids use the row index as a key by default. This prop can be used along with the columnKey prop to provide a custom key value.

ℹ️ Custom keys can ensure better UX for sortable or filterable grids, particularly if your cell components are stateful. Refer to the React documentation for more info.

⚠️ This prop cannot be auto-memoized because it is called during render. It is important to always useCallback for this prop; do not use an inline function.

scrollElement

Element that scrolls the grid, for grids that scroll along with other content (e.g. the page):

  • "window" to scroll with the page
  • an ancestor element that scrolls (e.g. stored with a useState ref callback); null until it has mounted

The grid renders at its full height and only renders the rows (and columns) visible within the scroll element's viewport. Its position within the scroll element is measured whenever it renders, scrolls, or resizes, and whenever content before it is resized, inserted, or removed (e.g. an image loading above the grid).

  • columns scroll with the scroll element too if the grid is as wide as its content (e.g. style={{ width: "max-content" }}); otherwise the grid fills the width of its parent and its columns scroll within it
  • scrollToCell, scrollToColumn and scrollToRow scroll whichever element scrolls each axis
  • defaultHeight and defaultWidth are used as the viewport size until the scroll element has been measured (e.g. during server rendering)
  • percentage row heights and column widths are relative to the scroll element's viewport
  • defaultScrollLeft and defaultScrollTop are ignored

ℹ️ While the scroll element is null, the grid renders the first rows (as it does during server rendering).

⚠️ The grid's onScroll handler is only called when the grid scrolls its own columns; listen to the scroll element's "scroll" events instead (or use the useIsScrolling hook).

tagName

Can be used to override the root HTML element rendered by the Grid component. The default value is "div", meaning that Grid renders an HTMLDivElement as its root.

⚠️ In most use cases the default ARIA roles are sufficient and this prop is not needed.