Giter Site home page Giter Site logo

dom-scroll-recycler's Introduction

DOM Scroll Recycler

A ReactJS wrapper component to limit DOM elements rendered.

This component takes in an array of items and calculates the amount of items to render, this can be done simply with the heights of the items and the height of the container or it can be pre calculated by the user and passed as a function with takes the current position and number of elements to show.

Installation

npm install dom-scroll-recycler

Props

  • items React.PropTypes.array - Array of JSX objects to render
  • itemHeight React.PropTypes.number - The height of each item in the list
  • offset React.PropTypes.number - The offset buffer that will allow for a more seamless scroll.
  • calculatePositionalValues React.PropTypes.func - Function to calculate the start and end position, as well as the paddingTop. This overrides the basic list calculation. If not given the basic calculation is used.

Other props on the DomScrollRecycler component are passed to the container. For example styles or onClick.

Example Usage

The example below renders a list with 100,000 items.

import React from 'react';
import ReactDOM from 'react-dom';
import DomScrollRecycler from 'dom-scroll-recycler';

class SingleItem extends React.Component {

  static propTypes = {
    id: PropTypes.number
  };


  render() {
    return(
      <div>
        This is {this.props.id}
      </div>
    );
  }
}

// Create 50,000 Example items
let items = [];
for (let i = 0; i <= 50000; i++) {
  items.push(<SingleItem index={i} />);
}

const onClickEvent = () => {
  //do something
};

ReactDOM.render(<DomScrollRecycler onClick={onClickEvent} items={items} itemHeight={20} offset={10} />, document.getElementById('list'));

So for example above, a list in a container sized 200px (this could be anything, it will figure it out once mounted), it will initially load 20 items, and will load a max of 30 in the DOM at any time.

dom-scroll-recycler's People

Contributors

danilosterrapid7 avatar philquinn avatar pquinn-r7 avatar rchirosca-r7 avatar rjacobs-r7 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.