malte-wessel / react-custom-scrollbars

React scrollbars component
http://malte-wessel.github.io/react-custom-scrollbars/
MIT License
3.2k stars 578 forks source link

react-custom-scrollbars dynamic content scroll #253

Open jai1331 opened 6 years ago

jai1331 commented 6 years ago

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.

xobotyi commented 6 years ago

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

naycho334 commented 5 years ago
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()
  }
 }