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

react-list

Package Overview
Dependencies
Maintainers
1
Versions
85
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-list

A versatile infinite scroll [React] component.

  • 0.8.17
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
324K
increased by4.32%
Maintainers
1
Weekly downloads
 
Created

What is react-list?

The react-list npm package is a versatile library for efficiently rendering large lists and tabular data in React applications. It provides a simple API to handle infinite scrolling, virtualized lists, and lazy loading, which helps in improving performance by only rendering the visible items.

What are react-list's main functionalities?

Simple List Rendering

This feature allows you to render a simple list of items. The `itemRenderer` function is used to define how each item should be rendered, and the `length` prop specifies the number of items in the list.

import React from 'react';
import ReactList from 'react-list';

class SimpleList extends React.Component {
  renderItem(index, key) {
    return <div key={key}>Item {index}</div>;
  }

  render() {
    return (
      <ReactList
        itemRenderer={this.renderItem.bind(this)}
        length={1000}
        type='uniform'
      />
    );
  }
}

export default SimpleList;

Infinite Scrolling

This feature demonstrates how to implement infinite scrolling. The `loadMoreItems` function is called when the user scrolls to the bottom of the list, adding more items to the state.

import React from 'react';
import ReactList from 'react-list';

class InfiniteScrollList extends React.Component {
  constructor(props) {
    super(props);
    this.state = { items: Array.from({ length: 20 }) };
  }

  loadMoreItems() {
    this.setState((prevState) => ({
      items: prevState.items.concat(Array.from({ length: 20 }))
    }));
  }

  renderItem(index, key) {
    return <div key={key}>Item {index}</div>;
  }

  render() {
    return (
      <div onScroll={(e) => {
        if (e.target.scrollHeight - e.target.scrollTop === e.target.clientHeight) {
          this.loadMoreItems();
        }
      }}>
        <ReactList
          itemRenderer={this.renderItem.bind(this)}
          length={this.state.items.length}
          type='uniform'
        />
      </div>
    );
  }
}

export default InfiniteScrollList;

Variable Height Items

This feature allows you to render a list with items of variable heights. The `type` prop is set to 'variable', and the `itemRenderer` function generates items with random heights.

import React from 'react';
import ReactList from 'react-list';

class VariableHeightList extends React.Component {
  renderItem(index, key) {
    const height = 30 + Math.random() * 100;
    return <div key={key} style={{ height }}>{`Item ${index} (height: ${height}px)`}</div>;
  }

  render() {
    return (
      <ReactList
        itemRenderer={this.renderItem.bind(this)}
        length={100}
        type='variable'
      />
    );
  }
}

export default VariableHeightList;

Other packages similar to react-list

FAQs

Package last updated on 29 Mar 2022

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