Package Exports
- react-scrollbar-size
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-scrollbar-size) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
React-Scrollbar-Size
React-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.
Installation
React-Scrollbar-Size is available as an npm package:
ℹ️ The examples referenced here relate to the 4.0.0 release candidate, which can be installed using the next tag. Earlier versions of the custom hook syntax can be viewed here. Earlier versions of the legacy component syntax can be viewed here.
$ npm install react-scrollbar-size@nextUsage
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.
TypeScript
import React, { 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
import React from 'react';
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.