# react-smooth-scrollbar

> React implementation of smooth-scrollbar

Latest version **8.0.6** (published 2017-10-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-smooth-scrollbar
pnpm add react-smooth-scrollbar
yarn add react-smooth-scrollbar
bun add react-smooth-scrollbar
```

## Health

**Score 18/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 8.0.6 |
| Published | 2017-10-26 |
| First published | 2016-02-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/react-smooth-scrollbar) |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 148 |
| Author | Dolphin Wood |
| Maintainers | dolphin_wood |
| Keywords | react, smooth, scroll, performance, scrollbar |

## Links

- npm: https://www.npmjs.com/package/react-smooth-scrollbar
- Repository: https://github.com/idiotWu/react-smooth-scrollbar
- Homepage: https://github.com/idiotWu/react-smooth-scrollbar#readme
- Issues: https://github.com/idiotWu/react-smooth-scrollbar/issues
- npm.io page: https://npm.io/package/react-smooth-scrollbar

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 8.0.6 (latest) — 2017-10-26
- 8.0.5 — 2017-10-16
- 8.0.4 — 2017-10-14
- 8.0.3 — 2017-10-12
- 8.0.2 — 2017-10-12
- 8.0.1 — 2017-10-08
- 7.2.2 — 2017-05-02
- 7.2.1 — 2016-12-12
- 7.2.0 — 2016-08-14
- 7.1.2 — 2016-07-25
- 7.1.1 — 2016-07-25
- 6.4.0 — 2016-07-14
- 6.3.3 — 2016-07-06
- 6.3.2 — 2016-06-24
- 6.3.1 — 2016-06-22
- … 18 more at https://npm.io/package/react-smooth-scrollbar/versions

## README

# react-smooth-scrollbar

[smooth-scrollbar](https://github.com/idiotWu/smooth-scrollbar) for react projects.

## Requirements

React 0.14+

## Install

```
npm install react-smooth-scrollbar smooth-scrollbar --save
```

## Demo

[http://idiotwu.github.io/react-smooth-scrollbar/](http://idiotwu.github.io/react-smooth-scrollbar/)

## Usage

```js
import React from 'react';
import ReactDOM from 'react-dom';
import Scrollbar from 'react-smooth-scrollbar';

class App extends React.Component {
    render() {
        return (
            <Scrollbar
                damping={number},
                thumbMinSize={number},
                syncCallbacks={boolean},
                renderByPixels={boolean},
                alwaysShowTracks={boolean},
                continuousScrolling={boolean},
                wheelEventTarget={element},
                plugins={object},
                onScroll={func},
            >
                your contents here...
            </Scrollbar>
        );
    }
}

ReactDOM.render(<App />, document.body);
```

### Available Options

| parameter | type | default | description |
| :--------: | :--: | :-----: | :---------- |
| damping | `number` | `0.1` | Momentum reduction damping factor, a float value between `(0, 1)`. The lower the value is, the more smooth the scrolling will be (also the more paint frames). |
| thumbMinSize | `number` | `20` | Minimal size for scrollbar thumbs. |
| renderByPixels | `boolean` | `true` | Render every frame in integer pixel values, set to `true` to improve scrolling performance. |
| alwaysShowTracks | `boolean` | `false` | Keep scrollbar tracks visible. |
| continuousScrolling | `boolean` | `true` | Set to `true` to allow outer scrollbars continue scrolling when current scrollbar reaches edge. |
| wheelEventTarget | `EventTarget` | `null` | Element to be used as a listener for mouse wheel scroll events. By default, the container element is used. This option will be useful for dealing with fixed elements.  |
| plugins | `object` | `{}` | Options for plugins, see [Plugin System](https://github.com/idiotWu/smooth-scrollbar/blob/master/docs/plugin.md). |


**Confusing with the option field? Try edit tool [here](http://idiotwu.github.io/smooth-scrollbar/)!**

## Using Scrollbar Plugins

```js
import { Component } from 'react';
import PropTypes from 'prop-types';
import SmoothScrollbar from 'smooth-scrollbar';
import OverscrollPlugin from 'smooth-scrollbar/plugins/overflow';
import Scrollbar from 'react-smooth-scrollbar';

SmoothScrollbar.use(OverscrollPlugin);

class App2 extends Component {
    render() {
        return (
            <Scrollbar> ... </Scrollbar>
        );
    }
}
```

## Get Scrollbar Instance

1. Use `ref` in **parent component**:

    ```javascript
    class Parent extends React.Component {
        componentDidMount() {
            const { scrollbar } = this.$container;
        }

        render() {
            return (
                <Scrollbar ref={c => this.$container = c}>
                    your content...
                </Scrollbar>
            );
        }
    }
    ```

2. Use `Context` in **child component**:

    ```javascript
    class Child extends React.Component {
        static contextTypes = {
            getScrollbar: React.PropTypes.func
        };

        componentDidMount() {
            this.context.getScrollbar((scrollbar) => {
                // ...
            });
        }

        render() {
            return <div> this is child component. </div>;
        }
    }

    class App extends React.Component {
        render(){
            return (
                <Scrollbar>
                    <Child />
                </Scrollbar>
            );
        }
    }
    ```


## APIs

[Documents](https://github.com/idiotWu/smooth-scrollbar/docs)

## License

MIT.

[![Sponsor](https://app.codesponsor.io/embed/haJ2RqCqwBLZtPKnMNBYgn4M/idiotWu/react-smooth-scrollbar.svg)](https://app.codesponsor.io/link/haJ2RqCqwBLZtPKnMNBYgn4M/idiotWu/react-smooth-scrollbar)

---
_Source: https://npm.io/package/react-smooth-scrollbar · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
