# react-scrollbar-size

> React hook to calculate the size of browser scrollbars

Latest version **5.0.0** (published 2022-05-07) · MIT license · 0 weekly downloads

## Install

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

## Health

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

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 5.0.0 |
| Published | 2022-05-07 |
| First published | 2017-03-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=14.0.0 |
| Dependencies | 0 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 27 |
| Author | Shawn McKnight |
| Maintainers | shawnmcknight |
| Keywords | react, scrollbar |

## Links

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

## 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

- 5.0.0 (latest) — 2022-05-07
- 4.0.0-rc.0 (rc) — 2021-04-04
- 4.0.0 — 2021-05-15
- 3.2.0 — 2021-03-12
- 3.1.1 — 2021-03-06
- 3.1.0 — 2020-11-07
- 3.0.1 — 2020-07-25
- 3.0.0 — 2020-07-18
- 3.0.0-rc.0 — 2020-07-18
- 2.1.0 — 2018-01-31
- 2.0.2 — 2017-10-06
- 2.0.1 — 2017-09-19
- 2.0.0 — 2017-05-30
- 1.0.2 — 2017-05-28
- 1.0.1 — 2017-04-26
- … 2 more at https://npm.io/package/react-scrollbar-size/versions

## README

# React-Scrollbar-Size

<div align="center">

React-Scrollbar-Size is a [React](https://reactjs.org/) hook designed to calculate the size of the user agent's horizontal and vertical scrollbars.
It will also detect when the size of the scrollbars change, such as when the user agent's zoom factor changes.

[![npm package](https://img.shields.io/npm/v/react-scrollbar-size/latest.svg)](https://www.npmjs.com/package/react-scrollbar-size)
[![npm downloads](https://img.shields.io/npm/dm/react-scrollbar-size)](https://www.npmjs.com/package/react-scrollbar-size)
[![CircleCI](https://circleci.com/gh/shawnmcknight/react-scrollbar-size.svg?style=shield)](https://circleci.com/gh/shawnmcknight/react-scrollbar-size/tree/main)
[![Code Climate](https://img.shields.io/codeclimate/maintainability/shawnmcknight/react-scrollbar-size)](https://codeclimate.com/github/shawnmcknight/react-scrollbar-size)
[![Code Style](https://badgen.net/badge/eslint/airbnb/ff5a5f?icon=airbnb)](https://github.com/airbnb/javascript)
[![Code style](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://prettier.io/)
[![Dependencies](https://img.shields.io/librariesio/release/npm/react-scrollbar-size)](https://libraries.io/npm/react-scrollbar-size)
[![Percentage of issues still open](https://isitmaintained.com/badge/open/shawnmcknight/react-scrollbar-size.svg)](https://isitmaintained.com/project/shawnmcknight/react-scrollbar-size)
![License](https://img.shields.io/npm/l/react-scrollbar-size)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-v2.0%20adopted-ff69b4.svg)](code_of_conduct.md)
[![Star on Github](https://img.shields.io/github/stars/shawnmcknight/react-scrollbar-size?style=social)](https://github.com/shawnmcknight/react-scrollbar-size)

</div>

## Installation

React-Scrollbar-Size is available as an [npm package](https://www.npmjs.com/package/react-scrollbar-size):

```sh
$ npm install react-scrollbar-size
```

## Usage

The `useScrollbarSize` custom hook returns an object with two properties:

| Name     | Description                                    |
| -------- | ---------------------------------------------- |
| `width`  | The current width of the vertical scrollbar    |
| `height` | The current height of the horizontal scrollbar |

## Examples

To see a live example, follow these [instructions](/example/README.md).

### TypeScript

```tsx
import { CSSProperties, FunctionComponent } from 'react';
import useScrollbarSize from 'react-scrollbar-size';

const styles: CSSProperties = {
  margin: '1rem',
  textAlign: 'center',
};

const ScrollbarSizeDemo: FunctionComponent = () => {
  const { height, width } = useScrollbarSize();

  return (
    <div style={styles}>
      <h2>React Scrollbar Size Demo</h2>
      <h4>Tip: Change browser zoom level to see scrollbar sizes change.</h4>
      <p>
        The current height of the scrollbar is {height}px.
        <br />
        The current width of the scrollbar is {width}px.
      </p>
    </div>
  );
};
```

### JavaScript

```jsx
import useScrollbarSize from 'react-scrollbar-size';

const styles = {
  margin: '1rem',
  textAlign: 'center',
};

const ScrollbarSizeDemo = () => {
  const { height, width } = useScrollbarSize();

  return (
    <div style={styles}>
      <h2>React Scrollbar Size Demo</h2>
      <h4>Tip: Change browser zoom level to see scrollbar sizes change.</h4>
      <p>
        The current height of the scrollbar is {height}px.
        <br />
        The current width of the scrollbar is {width}px.
      </p>
    </div>
  );
};
```

## License

This project is licensed under the terms of the
[MIT license](/LICENSE).

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