React Custom Scrollbars Component (Fork)

4.5.0 · active · verified Tue Apr 21

react-custom-scrollbars-2 is a community-maintained fork of the original `react-custom-scrollbars` package, providing a customizable React component for creating custom scrollbars while leveraging native browser scrolling behavior. It aims to address bug fixes and maintain active development where the original project became stale. The current stable version is 4.5.0. Key differentiators include frictionless native scrolling, mobile device native scrollbar support, extensive customization options (e.g., auto-hide, auto-height), universal rendering (SSR compatible), and performance optimizations using `requestAnimationFrame` for 60fps. It avoids extra stylesheets and ships with 100% code coverage. This package is ideal for applications requiring fine-grained control over scrollbar appearance and behavior without sacrificing performance or accessibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates rendering a `Scrollbars` component with basic styling, auto-hide functionality, and overflowing content.

import React, { Component } from 'react';
import { Scrollbars } from 'react-custom-scrollbars-2';

class App extends Component {
  render() {
    return (
      <div style={{ padding: '20px', border: '1px solid #ccc', maxWidth: '600px', margin: '50px auto' }}>
        <h1>My Content with Custom Scrollbars</h1>
        <Scrollbars 
          style={{ width: 500, height: 300, border: '1px solid #eee' }}
          autoHide
          autoHideTimeout={1000}
          autoHideDuration={200}
        >
          <p>Some great content that will overflow the container. This paragraph and subsequent content are here to demonstrate the scrolling functionality. </p>
          <p>You can customize the appearance and behavior of the scrollbars, such as making them automatically hide when not in use. This helps maintain a clean UI.</p>
          <p>More content to fill the space and ensure scrolling is necessary. Keep adding text until the scrollbar appears, allowing you to test the component effectively.</p>
          <p>Final paragraph for testing purposes. Enjoy your custom scrollbars!</p>
          <p>This is even more content to make sure the scrollbar is definitely there.</p>
          <p>And one last line.</p>
        </Scrollbars>
      </div>
    );
  }
}

// For a real app, you would render this component:
// ReactDOM.render(<App />, document.getElementById('root'));
export default App;

view raw JSON →