I was using the old version of perfect-scrollbar in my React app. In the old version, there was an ps.initialize() method that I was using with a ref to the section that I wanted to use perfect scrollbar for.
I tried the new approach -- see below -- but perfect scrollbar doesn't seem to be initializing.
import PerfectScrollbar from 'perfect-scrollbar';
class MyComponent extends Component {
componentDidMount() {
const sb1 = new PerfectScrollbar(this.refs.ref1);
const sb2 = new PerfectScrollbar(this.refs.ref2);
sb1.update();
sb2.update();
}
render() {
return(
<div ref="ref1">
Section 1
</div>
<div ref="ref2">
Section 2
</div>
);
}
}
export default MyComponent;
What's the right way to use perfect scrollbar in a React app? BTW, there's a React Wrapper for perfect scrollbar but it hasn't been updated for a while and this newly updated version of perfect-scrollbar has addressed some of the issues of the old one so I'd really like to use this one. I'd appreciate some pointers here. Thanks.
basically reading the documentation you can see the following:
to initialize:
therefore you can change your code to the following:
also it would be easy to use the wrapper that you mention, the idea of those kind of wrappers is to aliviate those initializations.
your code would end up like this:
note: you are not saying what version you are using, so I just assumed you were on the latest one :)