react-hook-scrolltop

React Hook for detecting when scrolled to top of page

Usage no npm install needed!

<script type="module">
  import reactHookScrolltop from 'https://cdn.skypack.dev/react-hook-scrolltop';
</script>

README

react-hook-scrolltop

React Hook for detecting if you're scrolled to the top of the window.

Install

npm install react-hook-scrolltop

Usage

Returns true when at the top of the page, false when the user scrolls away.

import React, { useState, useRef } from 'react'
import useScrollTop from 'react-hook-scrolltop'

const Header = () => {
  const isTopOfPage = useScrollTop();

  return (
    <header style={{ backgroundColor: isTopOfPage ? 'transparent' : 'white' }}>
      {...}
    </header>
  );
};

License

MIT