npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

rx-scrollable

v0.0.1

Published

This library is a fork of KingSora's `overlayscrollbars-react`. supports react >= 19, the purpose is to have a transition to new api - remove forwardedRef

Readme

rx-scrollable

This library is a fork of KingSora's overlayscrollbars-react. supports react >= 19, the purpose is to have a transition to new api - remove forwardedRef

Reference resource:
The vanilla JavaScript library OverlayScrollbars
React OverlayScrollbars for React

sponsor for KingSora

Installation

npm i rx-scrollable

Usage

The first step is to import the CSS file into your app:
main.tsx or root layout with Next layout.tsx

import 'overlayscrollbars/overlayscrollbars.css';

Note: If the path 'overlayscrollbars/overlayscrollbars.css' is not working use 'overlayscrollbars/styles/overlayscrollbars.css' as the import path for the CSS file.

Quick setup for window scroll

SPA (React only)

/* root/main.tsx */
import { provideWindowScroll } from 'rx-scrollable';

const root = createRoot(document.getElementById('root') as HTMLElement);
provideWindowScroll(true);

root.render(
  <StrictMode>
    <App />
  </StrictMode>
);

Next.js integration

  /* hydrate-scrollable.tsx */
'use client';
import { ProvideWindowScroll } from 'rx-scrollable';

export default function WindowScrollable() {
  return <ProvideWindowScroll defer />
}

add data-overlayscrollbars-initialize attr to html and body tag in layout.tsx

export default function RootLayout({ children }: { children: ReactNode }) {
  return (
    <html lang="en" data-overlayscrollbars-initialize> {/* -> add data-overlayscrollbars-initialize attr here */}
      <body className="bg-dark text-white px-4" data-overlayscrollbars-initialize> {/* -> add data-overlayscrollbars-initialize attr here */}
        <WindowScrollable />  {/* add WindowScrollable */}
        {children}
      </body>
    </html>
  );
}

Component

The main entry point is the Scrollable which can be used in your application as a component:

import { Scrollable } from "rx-scrollable";
<Scrollable
  element="div" /*is default*/
  options={{ scrollbars: { autoHide: 'scroll' } }}
  events={{ scroll: () => { /* ... */ } }}
  defer
/>

Ref

The ref of the Scrollable will give you an object with which you can access the OverlayScrollbars instance and the root element of the component.
The ref object has two properties:

  • osInstance: a function which returns the OverlayScrollbars instance.
  • getElement: a function which returns the root element.

Hook

In case the Scrollable is not enough, you can also use the useOverlayScrollbars hook:

import { useOverlayScrollbars } from "rx-srcollable";

// example usage
const YourScollableComponent = () => {
  const ref = useRef();
  const [initialize, instance] = useOverlayScrollbars({ options, events, defer });
  
  useEffect(() => {
    initialize(ref.current);
  }, [initialize]);
  
  return <div ref={ref} />
}

The hook is for advanced usage and lets you control the whole initialization process. This is useful if you want to integrate it with other plugins such as react-window or react-virtualized.

The hook will destroy the instance automatically if the component unmounts.

Parameters

Parameters are optional and similar to the OverlayScrollbarsComponent. Its an object with optional properties:

  • options: accepts an object which represents the OverlayScrollbars options.
  • events: accepts an object which represents the OverlayScrollbars events.
  • defer: accepts an boolean or object. Defers the initialization to a point in time when the browser is idle.

Return

The useOverlayScrollbars hook returns a tuple with two values:

  • The first value is the initialization function, it takes one argument which is the InitializationTarget.
  • The second value is a function which returns the current OverlayScrollbars instance or null if not initialized.

Note: The identity of both functions is stable and won't change, thus they can safely be used in any dependency array.

License

MIT