# react-scroll-percentage-hook

> A React hook to monitor component scroll percentage.

Latest version **1.2.2** (published 2023-11-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-scroll-percentage-hook
pnpm add react-scroll-percentage-hook
yarn add react-scroll-percentage-hook
bun add react-scroll-percentage-hook
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2023-11-06 |
| First published | 2022-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 8 |
| Author | Vadim Rogov |
| Maintainers | vdmrgv |
| Keywords | react, hooks, react-hooks, percentage, scroll percentage, progress, scroll progress, scroll, scrolling |

## Links

- npm: https://www.npmjs.com/package/react-scroll-percentage-hook
- Repository: https://github.com/vdmrgv/react-scroll-percentage-hook
- Homepage: https://vdmrgv.github.io/react-scroll-percentage-hook
- Issues: https://github.com/vdmrgv/react-scroll-percentage-hook/issues
- npm.io page: https://npm.io/package/react-scroll-percentage-hook

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

- 1.2.2 (latest) — 2023-11-06
- 1.2.1 — 2023-03-28
- 1.2.0 — 2023-03-21
- 1.1.0 — 2023-02-15
- 1.0.5 — 2022-10-26
- 1.0.4 — 2022-10-13
- 1.0.3 — 2022-10-12
- 1.0.2 — 2022-10-12
- 1.0.1 — 2022-10-12

## README

# react-scroll-percentage-hook

[![Version Badge][npm-version-svg]][package-url]
![NPM license][license-image]
[![GZipped size][npm-minzip-svg]][bundlephobia-url]
[![PRs Welcome][pr-svg]][pr-url]
[![Downloads][downloads-image]][downloads-url]
[![NPM total downloads][total-downloads-svg]][total-downloads-url]

A React hook that reports the element's current scroll percentage. Can be used for both scroll axes.
<br />
Check out [the demo](https://vdmrgv.github.io/react-scroll-percentage-hook) for some examples.

## Features

- 🚀 **Fast** - Built with hooks and functional components only.
- 📏 **No need to specify sizes** - No need to pass the dimensions of the component, scrollbar or element
- 👫 **Cross-browser** - Works out-of-the-box for most browsers, regardless of version.
- 📲 **Mobile-friendly** - Supports mobile devices and touch screens.
- 🛠 **Written in TypeScript** - It'll fit right into your existing TypeScript
  project
- 💥 **Lightweight** - Around `~400B`

## Install

```bash
  # with npm
  npm install --save react-scroll-percentage-hook
  # with yarn
  yarn add react-scroll-percentage-hook
```

## Usage

```js
import useScrollPercentage from 'react-scroll-percentage-hook';

const Component = () => {
  // TypeScript example:
  // const { ref, percentage } = useScrollPercentage<HTMLDivElement>(...props);
  const { ref, percentage } = useScrollPercentage();

  return (
    <>
      <p>{`vertical: ${percentage.vertical} horizontal: ${percentage.horizontal}`}</p>
      <div ref={ref}>
        {items.map((item, index) => (
          <div key={index}>{item}</div>
        ))}
      </div>
    </>
  );
};
```

## API

| Name               | Description                                                          | Type          | Required | Default Value |
| ------------------ | -------------------------------------------------------------------- | ------------- | :------: | ------------- |
| windowScroll       | If enabled uses window scroll                                        | `boolean`     | ❌        | `false`       |
| onProgress         | Callback called when scrolling `({ vertical, horizontal }) => void`   | `function`    | ❌        | `undefined`   |
| timeout            | Timeout for scroll handler in `ms`                                   | `number`      | ❌        | `10`          |


## Supported Browsers
`react-scroll-percentage-hook` does not have a specific API to work with, so it supports all browsers from early versions and will support all evergreen browsers and the latest mobile browsers for iOS and Android. IE 9+ is also supported.

If you find a browser-specific problem, please report it.

## Contributing

Please read through our [contributing guidelines](https://github.com/vdmrgv/react-scroll-percentage-hook/blob/main/CONTRIBUTING.md). Included are directions for opening issues, coding standards, and notes on development.

## License

Code released under the [MIT License][license-url].

[package-url]: https://npmjs.org/package/react-scroll-percentage-hook
[npm-version-svg]: https://img.shields.io/npm/v/react-scroll-percentage-hook.svg
[npm-version-svg]: https://img.shields.io/npm/v/react-scroll-percentage-hook.svg
[npm-minzip-svg]: https://img.shields.io/bundlephobia/minzip/react-scroll-percentage-hook.svg
[bundlephobia-url]: https://bundlephobia.com/result?p=react-scroll-percentage-hook
[license-image]: https://img.shields.io/npm/l/react-scroll-percentage-hook.svg?style=flat
[license-url]: LICENSE
[pr-svg]: https://badgen.net/badge/PRs/welcome/cyan
[pr-url]: http://makeapullrequest.com
[downloads-image]: http://img.shields.io/npm/dm/react-scroll-percentage-hook.svg
[downloads-url]: http://npm-stat.com/charts.html?package=react-scroll-percentage-hook
[total-downloads-svg]: https://img.shields.io/npm/dt/react-scroll-percentage-hook.svg?style=flat
[total-downloads-url]: https://npmcharts.com/compare/react-scroll-percentage-hook?minimal=true

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