@aaronhayes/react-scroll-hook

The easiest way to detect current element in view when using react-scroll

Usage no npm install needed!

<script type="module">
  import aaronhayesReactScrollHook from 'https://cdn.skypack.dev/@aaronhayes/react-scroll-hook';
</script>

README

React Scroll Hook

npm (scoped) Bundle Size License

Hook for watching vertical scrolling location when using React Scroll

Install

$ npm install --save @aaronhayes/react-scroll-hook
$ yarn add @aaronhayes/react-scroll-hook

Usage

import { Link, Element , Events, animateScroll as scroll, scrollSpy, scroller } from 'react-scroll'


import useScrollSpy from '@aaronhayes/react-scroll-hook';

const MyScrollWatchingComponent = () => {
    const location = useScrollSpy();
    console.log(location);
    // Location will either be undefined or the current element scrolled to.

    return (
        <div>
            <h1>
                You are currently scrolled to: {location}
            </h1>
        </div>
    )
}

See Also