Skip to content

useScroll

Tracks the current scroll position of the provided element.

Usage

import { useRef } from "react";
import { useScroll } from "@/hooks/browser/use-scroll";
const Component = () => {
const ref = useRef<HTMLDivElement>(null);
const { x, y } = useScroll(ref);
return (
<div ref={ref}>
<p>Scroll X: {x}</p>
<p>Scroll Y: {y}</p>
</div>
);
};

Installation

Terminal window
npx atmx add hook use-scroll