# scroll-data-hook

> React Hook that helps getting useful information about viewport scrolling

Latest version **1.0.4** (published 2020-07-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install scroll-data-hook
pnpm add scroll-data-hook
yarn add scroll-data-hook
bun add scroll-data-hook
```

## Health

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

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2020-07-16 |
| First published | 2019-12-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 63.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 141 |
| Author | dejorrit |
| Maintainers | dejorrit |

## Links

- npm: https://www.npmjs.com/package/scroll-data-hook
- Repository: https://github.com/dejorrit/scroll-data-hook
- Homepage: https://github.com/dejorrit/scroll-data-hook#readme
- Issues: https://github.com/dejorrit/scroll-data-hook/issues
- npm.io page: https://npm.io/package/scroll-data-hook

## Recent versions

- 1.0.4 (latest) — 2020-07-16
- 1.0.3 — 2020-07-15
- 1.0.2 — 2020-07-09
- 1.0.1 — 2019-12-28
- 1.0.0 — 2019-12-26

## README

# Scroll Data Hook

[![NPM](https://img.shields.io/npm/v/scroll-data-hook.svg)](https://www.npmjs.com/package/scroll-data-hook)

The `useScrollData` hook returns information about scroll speed, distance, direction and more. Useful when building dynamic navigation bars or doing other scroll related UI updates.

Check out [the demo](https://dejorrit.github.io/scroll-data-hook/).

## Installation

```bash
yarn add scroll-data-hook
```

## Usage

```tsx
import * as React from "react";
import { useScrollData } from "scroll-data-hook";

const MyComponent = () => {
  const {
    scrolling,
    time,
    speed,
    direction,
    position,
    relativeDistance,
    totalDistance
  } = useScrollData({
    onScrollStart: () => {
      console.log('Started scrolling);
    },
    onScrollEnd: () => {
      console.log('Finished scrolling);
    }
  });

  return (
    <div>
      <p>
        {scrolling ? 'Scrolling' : 'Not scrolling'}
      </p>

      <p>
        Scrolling time: {time} milliseconds
      </p>

      <p>
        Horizontal speed: {speed.x} pixels per second
      </p>

      <p>
        Vertical speed: {speed.y} pixels per second
      </p>

      <p>
        Direction: {direction.x} {direction.y}
      </p>

      <p>
        Relative distance: {relativeDistance.x}/{relativeDistance.y}
      </p>

      <p>
        Total distance: {totalDistance.x}/{totalDistance.y}
      </p>
    </div>
  )
};
```

## License

MIT © [dejorrit](https://github.com/dejorrit)

---

This hook is created using [create-react-hook](https://github.com/hermanya/create-react-hook).

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