1.0.1 • Published 5 years ago

react-hook-scrolltop v1.0.1

Weekly downloads
91
License
MIT
Repository
github
Last release
5 years ago

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