0.3.0 • Published 8 years ago

react-infinitum v0.3.0

Weekly downloads
5
License
MIT
Repository
github
Last release
8 years ago

React Infinitum

React Infinitum is a window infinite scroll loader

Install

npm install --save react-infinitum

Usage

import React from 'react';
import Infinitum from 'react-infinitum';

let fakeData = [
  {city: 'Curitiba', country: 'Brazil'},
  {city: 'New York', country: 'United States'},
  {city: 'Tokyo', country: 'Japan'}
];

class Feeds extends React.Component {
  constructor(props) {
    super(props);

    this.state = {
      cities: fakeData,
      loadMore: true
    };
  }

  loadMoreCities() {
    // Set loadMore to false and ReactInfinitum will be blocked
    this.setState({
      loadMore: false
    });

    // Simulate an AJAX request
    ajax.get('/cities')
      .then(res => {
        this.setState({
          cities: this.state.cities.concat(res),
          loadMore: true
        });
      })
      .catch(() => {
        // No more cities
        this.setState({
          loadMore: false
        });
      });
  }

  render() {
    return (
      <Infinitum onReachBottom={this.loadMoreCities.bind(this)} loadMore={this.state.loadMore}>
        {this.state.cities.map((city, i) => {
          return (
            <div key={i}>
              <p>{city.city}</p>
              <p>{city.country}</p>
            </div>
          );
        })}
      </Infinitum>
    );
  }
}

export default Feeds;

Properties

NameTypeRequired?Default ValueDescription
onReachBottomfunctionYes-The callback that will be fired when window reach the page bottom
loadMorebooleanNotrueThe flag that indicate if will call the callback
triggernumberNo0.85A number between 0 - 1 that indicate the window scroll percentage to reach on page bottom