React-custom-scrollbars: End of scroll hook?

Created on 25 Apr 2016  路  1Comment  路  Source: malte-wessel/react-custom-scrollbars

Hi

I am trying to implement an infinite scroll component using this.

Is there any way to hook into the scroll event and say something like if the scrollTop is within 50px of the bottom, then fire a callback?

question

Most helpful comment

You can easily implement this with the following code:

const MyScrollbars = createClass({
  handleAboutToReachBottom() {
    // load more
  }
  handleUpdate(values) {
    const { scrollTop, scrollHeight, clientHeight } = values;
    const pad = 100; // 100px of the bottom
    // t will be greater than 1 if we are about to reach the bottom
    const t = ((scrollTop + pad) / (scrollHeight - clientHeight));
    if (t > 1) this.handleAboutToReachBottom();
  },
  render() {
    return <Scrollbars onUpdate={this.handleUpdate}/>;
  }
});

Have a look at the API Documentation

>All comments

You can easily implement this with the following code:

const MyScrollbars = createClass({
  handleAboutToReachBottom() {
    // load more
  }
  handleUpdate(values) {
    const { scrollTop, scrollHeight, clientHeight } = values;
    const pad = 100; // 100px of the bottom
    // t will be greater than 1 if we are about to reach the bottom
    const t = ((scrollTop + pad) / (scrollHeight - clientHeight));
    if (t > 1) this.handleAboutToReachBottom();
  },
  render() {
    return <Scrollbars onUpdate={this.handleUpdate}/>;
  }
});

Have a look at the API Documentation

Was this page helpful?
0 / 5 - 0 ratings

Related issues

anupmishra203 picture anupmishra203  路  3Comments

mhemrg picture mhemrg  路  4Comments

limbosounds picture limbosounds  路  4Comments

strobox picture strobox  路  4Comments

hank7444 picture hank7444  路  5Comments