react-custom-scrollbars dynamic content scroll

Created on 25 Apr 2018  路  2Comments  路  Source: malte-wessel/react-custom-scrollbars

I have been using react-custom-scrollbars for custom scrolling in my app, there comes a point, the data would be dynamic and scroll should go to bottom or recent data added.

simple react-custom-scrollbar looks like below:

 import { Scrollbars } from 'react-custom-scrollbars';

 class App extends Component {
   render() {
     return (
       <Scrollbars style={{ width: 500, height: 300 }}>
         <p>Some great content...</p>
       </Scrollbars>
     );
   }
 }

above code works fine, In my case the content

Some great content...

is dynamic.

tried adding dynamic data and done with it, the real problem occurred in scroll. The scroll should go to an element added recently, and it worked but it stopped working the native scroll functionality after that.

You can see the entire code here

Any help on this really appreciated.

All 2 comments

@jai1331 Aactualy it works as it should=)
setState() triggering componentDidUpdate() which scrolls the content to the top.

import { Scrollbars } from 'react-custom-scrollbars';

 class App extends Component {
   render() {
     return (
       <Scrollbars 
               style={{ width: 500, height: 300 }}
               ref={ e=> this.scrollBar = e }
               onUpdate={ this.handleUpdate.bind( this ) }
       >
         <p>Some great content...</p>
       </Scrollbars>
     );
   }
  handleUpdate(){
     this.scrollBar.scrollToBottom()
  }
 }
Was this page helpful?
0 / 5 - 0 ratings