React-custom-scrollbars: Start on bottom?

Created on 19 Jun 2016  路  8Comments  路  Source: malte-wessel/react-custom-scrollbars

Good afternoon.
Is possible will start (load) in bottom position?
_Yes, i am known when i can scrollToBottom() on loading, but in this case will animation. It spoils UI ((`_

Thanks.

question

Most helpful comment

Add a ref to the <Scrollbars ref="scrollbars"/> component, then call this.refs.scrollbars.scrollToBottom().

Update

In the new React versions you will have to call the scrollToBottom method on the scrollbars ref like this.

class MyComponent extends React.Component {
  scrollbars = React.createRef();
  state = {
    mounted: false,
  }

  componentDidMount() {
    this.setState({mounted: true});
  }

  componentDidUpdate() {
    this.state.mounted && this.scrollbars.current.scrollToBottom();
  }

  render() {
    return <Scrollbars ref={this.scrollbars}/>;
  }
}

All 8 comments

I'm not sure that this is possible. The library uses the native scrolling behaviour of the browser, and I'm not aware of any solution for this.

it would be good that this option is added!
For sites that use a tchat is handy

Add a ref to the <Scrollbars ref="scrollbars"/> component, then call this.refs.scrollbars.scrollToBottom().

Update

In the new React versions you will have to call the scrollToBottom method on the scrollbars ref like this.

class MyComponent extends React.Component {
  scrollbars = React.createRef();
  state = {
    mounted: false,
  }

  componentDidMount() {
    this.setState({mounted: true});
  }

  componentDidUpdate() {
    this.state.mounted && this.scrollbars.current.scrollToBottom();
  }

  render() {
    return <Scrollbars ref={this.scrollbars}/>;
  }
}

@Enijar Worked for me. Thanks.

Add a ref to the <Scrollbars ref="scrollbars"/>

component, then call this.refs.scrollbars.scrollToBottom().

i called this.refs.scrollbars.scrollToBottom() in componentDidMount(), doesn't work

is there is any alternative to "refs"?

@deepika1223 yes, you can do like this:

constructor(props){ super(props); this.msgsScrollbars = React.createRef(); }

componentDidMount(){ this.msgsScrollbars.current.scrollToBottom(); }

<Scrollbars ref={this.msgsScrollbars}>

@Agrafador Your solution works but, the initial render starts from the top and jumps to the bottom when componentDidMount() is called. Any solution with componentWillMount() ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ilfa picture ilfa  路  5Comments

limbosounds picture limbosounds  路  4Comments

dusanstojanovic picture dusanstojanovic  路  3Comments

danmo picture danmo  路  4Comments

elinake picture elinake  路  4Comments