react-hook-scrolltop
v1.0.1
Published
React Hook for detecting when scrolled to top of page
Downloads
8
Maintainers
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>
);
};