0.1.0 • Published 4 years ago

@hermanwikner/react-scroll-direction v0.1.0

Weekly downloads
23
License
MIT
Repository
github
Last release
4 years ago

React Scroll Direction

A React hook to detect scroll direction.

Get started

npm i @hermanwikner/react-scroll-direction

Usage

Wrap your app in the ScrollDirectionProvider component and then use the useScrollDirection hook. The hook returns "UP" or "DOWN".

Example:

// App.js

import React from 'react';
import { ScrollDirectionProvider } from '@hermanwikner/react-scroll-direction';

const App = () => {
  return <ScrollDirectionProvider>{/* Your app code here */}</ScrollDirectionProvider>;
}
// Example.js

import React from 'react';
import { useScrollDirection } from '@hermanwikner/react-scroll-direction';

const Example = () => {
  
    const direction = useScrollDirection();

    const style = {
        position: 'fixed',
        top: '50%',
        left: '50%',
        transform: 'translate(-50%,-50%)',
        color: direction === 'UP' ? 'lightcoral' : 'lightblue'
    }

    return <h1 style={style}>{direction}</h1>
}

export default Example;
0.1.0

4 years ago

0.0.0

4 years ago

9.9.10

4 years ago

9.9.11

4 years ago

9.9.9

4 years ago

1.1.1

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago