simple-scrollbar
simple-scrollbar copied to clipboard
How to integrate it with reactjs ?
Create a component which is working with DOM using ref
Actually, it appears that simply including import SimpleScrollbar from 'simple-scrollbar'; in a React component yields an app crash and the error: "Unhandled Rejection (ReferenceError): window is not defined".
Something along the lines:
import React from 'react'
import SimpleScrollbar from 'simple-scrollbar'
import 'simple-scrollbar/simple-scrollbar.css'
class Scroller extends React.Component {
constructor(...args) {
super(...args)
this.div = React.createRef()
}
componentDidMount() {
SimpleScrollbar.initEl(this.div.current)
}
render() {
return (
<div className="Scroller" ref={this.div}>
{/* your content goes here */}
</div>
)
}
}
I have open sourced a react version of the library (and I also updated the code while building it, so it works even better than this one).
For anyone interested: https://github.com/closeio/react-custom-scroller