In react "^15.4.1", I want to display middle section of a page after reload. So I am trying to do it using scrollbar but I am getting an error like,
main.js:43122 Uncaught TypeError: Cannot read property 'scrollTop' of null
at ref (main.js:43122)
at detachRef (main.js:82172)
at Object.ReactRef.detachRefs (main.js:82227)
at Object.receiveComponent (main.js:10145)
at ReactCompositeComponentWrapper._updateRenderedComponent (main.js:77618)
Importing like, import { Scrollbars } from 'react-custom-scrollbars';
and the version is 4.0.1
In .jsx file,
componentDidMount() {
this.scrollTop(200);
}
handleScrolling = (frame) => {
if(frame.top === 1) this.setState({ loading: true })
}
scrollTop = (value) => {
if(this.refs.scrollbar) this.refs.scrollbar.scrollTop(value);
}
<Scrollbars
ref={(scrollbar) => {scrollbar.scrollTop(200);}}
style={{ height: '100vh' }} onScrollFrame={this.handleScrolling}>
...
How can I fix this issue? Actually I am new to ReactJS. Please help me regarding the same.