React Custom Scrollbars

4.2.1 · active · verified Sun Apr 19

react-custom-scrollbars is a React component library designed to replace native browser scrollbars with fully customizable alternatives, offering a consistent look and feel across different browsers and devices. It prioritizes performance with `requestAnimationFrame` for smooth scrolling and supports universal rendering (SSR). Key features include auto-hide, auto-height, and extensive styling options without requiring external stylesheets. The current stable version is 4.2.1. While not on a fixed release cadence, the project has seen consistent updates in its 4.x series, primarily focusing on React compatibility and bug fixes. It differentiates itself by its focus on native-like behavior, mobile support, and complete visual control, contrasting with simpler scroll solutions or those that inject complex CSS.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic React class component utilizing `Scrollbars` with fixed dimensions to manage overflowing content, showcasing the default custom scrollbar appearance and behavior.

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

class CustomScrollbarExample extends Component {
  render() {
    // Simulate dynamic content that would typically exceed container height
    const longContent = Array.from({ length: 50 }).map((_, i) => (
      <p key={i} style={{ marginBottom: '8px', lineHeight: '1.4' }}>
        This is line {i + 1} of scrollable content. It demonstrates how{' '}
        <span style={{ fontWeight: 'bold' }}>react-custom-scrollbars</span> handles overflow{' '}
        with its custom scroll mechanism. The content within the Scrollbars component will be
        wrapped and managed.
      </p>
    ));

    return (
      <div style={{ padding: '20px', fontFamily: 'Arial, sans-serif', maxWidth: '800px', margin: '0 auto' }}>
        <h1>Custom Scrollbar Example</h1>
        <p>
          Below is a `Scrollbars` component configured with a fixed width and height.
          The content inside will scroll using the custom scrollbars provided by the library.
        </p>
        <div style={{ border: '1px solid #e0e0e0', borderRadius: '4px', overflow: 'hidden' }}>
          <Scrollbars style={{ width: '100%', height: 300 }}>
            {longContent}
          </Scrollbars>
        </div>
        <p style={{ marginTop: '20px' }}>
          This shows the basic usage, allowing for a visually consistent scroll experience
          across different browsers and operating systems, with full control over the scrollbar's appearance.
        </p>
      </div>
    );
  }
}

export default CustomScrollbarExample;

view raw JSON →