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';


React Scroll Hook

npm (scoped) Bundle Size License

Hook for watching vertical scrolling location when using React Scroll


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


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

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

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

    return (
                You are currently scrolled to: {location}

See Also