2.0.5 • Published 12 months ago

@beskar-labs/use-sticky v2.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
12 months ago

useSticky

useSticky is a tiny, zero-dependency 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 @beskar-labs/use-sticky

Usage

import { useSticky } from '@beskar-labs/use-sticky';

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

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

12 months ago

2.0.4

12 months ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.1

1 year ago