Registry / web-framework / react-custom-scrollbars-2

react-custom-scrollbars-2

JSON →
library4.5.0jsnpmunverified

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.

npm install react-custom-scrollbars-2
INSTALL
IMPORT
SIG · REACT-CUSTOM-SCROL
R
react-custom-scrollbars-2
web-frameworkjavascriptv4.5.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Scrollbars
import { Scrollbars } from 'react-custom-scrollbars-2';
const { Scrollbars } = require('react-custom-scrollbars-2');
The library primarily uses named exports. CommonJS `require` works but ESM `import` is the recommended modern approach and supported by TypeScript.
ScrollbarProps
import type { ScrollbarProps } from 'react-custom-scrollbars-2';
When using TypeScript, import `ScrollbarProps` for type annotations on component props or direct manipulation.
Scrollbars (as default)
import Scrollbars from 'react-custom-scrollbars-2/lib/Scrollbars';
import Scrollbars from 'react-custom-scrollbars-2';
While the main export is named, some bundlers or older setups might interpret `import Scrollbars from 'pkg'` as a default import. Always use named `import { Scrollbars }` from the root for clarity and consistency. The default export might be from a specific path.

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;
Debug
Known issues
gotchaThis package is a fork of the original `react-custom-scrollbars`. While it aims for bug fixes and active maintenance, be aware of the lineage when migrating from the original package, as specific behavioral changes or new bugs might exist that differ from the original's last stable release.
fix
Review the GitHub repository's issues and changelog for specific differences or migration notes if coming from the original `react-custom-scrollbars`.
affects: >=4.0.0
gotchaWhen using `autoHeight`, ensure `autoHeightMin` and `autoHeightMax` are set appropriately to prevent layout shifts or incorrect sizing, especially if the content height can vary wildly. Default values might not always suit your specific use case.
fix
Explicitly define `autoHeightMin` and `autoHeightMax` props to control the scrollable area's boundaries based on your design requirements.
affects: >=4.0.0
gotchaCustom rendering components (`renderView`, `renderThumbHorizontal`, etc.) must pass `ref` to their children if they internally use `ref` to manage scrollbar elements. Failure to do so can break internal calculations or event handling.
fix
Ensure your custom render functions correctly forward `ref` props received from `Scrollbars` to the underlying DOM elements or React components that need them.
affects: >=4.0.0
Errors
Common errors & fixes
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined.
Incorrect import of `Scrollbars` component, often due to a default import instead of a named import.
fix
Change `import Scrollbars from 'react-custom-scrollbars-2';` to `import { Scrollbars } from 'react-custom-scrollbars-2';`
TypeError: Cannot read properties of undefined (reading 'current')
Often occurs when trying to access `this.refs.scrollbars.getScrollHeight()` or similar methods, indicating `this.refs` is not properly set up or the component is not yet mounted.
fix
Ensure the component is fully mounted before attempting to access its instance methods. For functional components, use `useRef` and ensure the ref is attached to the `Scrollbars` component and has been assigned.
Scrollbars are not appearing or styled correctly despite applying custom render props.
Commonly, the custom `renderView`, `renderTrack`, or `renderThumb` components do not correctly apply the style and props provided to them by the `Scrollbars` component.
fix
Ensure your custom render functions correctly spread `props` (e.g., `<div {...props} />`) and apply `style` when provided, as these are crucial for positioning and visibility.
Upgrade
Version history
4.5.0latest on npm
Audit
Dependencies
reactrequiredRequired peer dependency for rendering React components.
react-domrequiredRequired peer dependency for ReactDOM operations.
Agent activity
42 hits · last 30 days
node
38
OpenAI (training)
1
Resources
react-custom-scrollbars-2 — npm install react-custom-scrollbars-2 · libregistry