JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1371
  • Score
    100M100P100Q113188F
  • License MIT

Package Exports

  • use-scroll-direction

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 (use-scroll-direction) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

use-scroll-direction

A simple, performant and versatile hook for handling scroll in your react app.

Installation

npm i use-scroll-direction

Usage

The hook returns the actual scroll direction which could be one of three states: 'NONE', 'DOWN', 'UP';

On window

import {useScrollDirection} from "use-scroll-direction";

export const WindowExample = () => {
    const scrollDirection = useScrollDirection();
    useEffect(() => {
        console.log(scrollDirection)
    }, [scrollDirection]);

    return (
      <div>{...}</div>
    )
};

On the element ref

import {useScrollDirection} from "use-scroll-direction";

export const ComponentRefExample = () => {
    const elementRef = useRef(null);
    const scrollDirection = useScrollDirection({ref: elementRef});

    return (
        <div ref={elementRef} style={{height: '100vh', overflowY: 'scroll'}} >
            <div>{...}</div>
        </div>
    )
};

For more specific examples, check the demo app in ./example