Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 430 Bytes

useScroll.md

File metadata and controls

27 lines (20 loc) · 430 Bytes

useScroll

React sensor hook that re-renders when the scroll position in a DOM element changes.

Usage

import {useScroll} from 'react-use';

const Demo = () => {
  const scrollRef = React.useRef(null);
  const {x, y} = useScroll(scrollRef);

  return (
    <div ref={scrollRef}>
      <div>x: {x}</div>
      <div>y: {y}</div>
    </div>
  );
};

Reference

useScroll(ref: RefObject<HTMLElement>);