mirror of
https://github.com/nextui-org/nextui.git
synced 2025-12-08 19:26:11 +00:00
* refactor: migrate eslint to v9 * chore: lint * chore: update eslint command * chore: fix lint warnings * chore: separate lint and lint:fix * chore: exclude contentlayer generated code * fix(scripts): add missing await
21 lines
519 B
TypeScript
21 lines
519 B
TypeScript
import * as React from "react";
|
|
|
|
export function useScrollPosition(ref: React.MutableRefObject<HTMLElement | null>) {
|
|
const [scrollPosition, setScrollPosition] = React.useState(0);
|
|
|
|
React.useEffect(() => {
|
|
const handleScroll = () => {
|
|
setScrollPosition(ref.current?.scrollTop || 0);
|
|
};
|
|
|
|
ref.current?.addEventListener("scroll", handleScroll);
|
|
|
|
// Cleanup on unmount
|
|
return () => {
|
|
ref.current?.removeEventListener("scroll", handleScroll);
|
|
};
|
|
}, []);
|
|
|
|
return scrollPosition;
|
|
}
|