1.0.2 • Published 2 years ago

@haydenbleasel/use-sticky v1.0.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

useSticky

useSticky is a tiny, SSR-friendly hook for tracking element sticky state. It implements a hack of margin-top: -1px to detect when an element is stuck to the top of the viewport and returns a boolean value.

Example

Installation

yarn add @haydenbleasel/use-sticky

Usage

import useSticky from '@haydenbleasel/use-sticky';

const App = () => {
  const ref = useRef(null);
  const isSticky = useSticky(ref);

  return (
    <div ref={ref}>
      <p>Is sticky? {isSticky ? 'Yes' : 'No'}</p>
    </div>
  );
};
1.0.2

2 years ago

1.0.1

2 years ago