React hook to calculate the size of browser scrollbars
npm install react-scrollbar-sizeReact-Scrollbar-Size is a React 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.








!License


React-Scrollbar-Size is available as an npm package:
``sh`
$ npm install react-scrollbar-size
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 |
To see a live example, follow these instructions.
`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 (
The current height of the scrollbar is {height}px.
The current width of the scrollbar is {width}px.
$3
`jsx
import useScrollbarSize from 'react-scrollbar-size';const styles = {
margin: '1rem',
textAlign: 'center',
};
const ScrollbarSizeDemo = () => {
const { height, width } = useScrollbarSize();
return (
React Scrollbar Size Demo
Tip: Change browser zoom level to see scrollbar sizes change.
The current height of the scrollbar is {height}px.
The current width of the scrollbar is {width}px.
);
};
``This project is licensed under the terms of the
MIT license.