react-hook-scrolltop

1.0.1 • Public • Published

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

Package Sidebar

Install

npm i react-hook-scrolltop

Weekly Downloads

0

Version

1.0.1

License

MIT

Unpacked Size

5.24 kB

Total Files

7

Last publish

Collaborators

  • cabe