simple-scrollbar icon indicating copy to clipboard operation
simple-scrollbar copied to clipboard

How to integrate it with reactjs ?

Open ramisalem opened this issue 7 years ago • 4 comments

ramisalem avatar Oct 10 '18 16:10 ramisalem

Create a component which is working with DOM using ref

Beraliv avatar Oct 13 '18 12:10 Beraliv

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".

tatwater avatar Nov 11 '18 18:11 tatwater

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>
    )
  }
}

Edit simple-scrollbar

buzinas avatar Dec 06 '18 19:12 buzinas

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

buzinas avatar Jun 13 '20 18:06 buzinas