mirror of
https://github.com/hanzo-apps/dataroom.git
synced 2026-10-30 14:47:36 +00:00
24 lines
545 B
TypeScript
24 lines
545 B
TypeScript
import * as React from "react";
|
|
|
|
export function useAtBottom(offset = 0) {
|
|
const [isAtBottom, setIsAtBottom] = React.useState(false);
|
|
|
|
React.useEffect(() => {
|
|
const handleScroll = () => {
|
|
setIsAtBottom(
|
|
window.innerHeight + window.scrollY >=
|
|
document.body.offsetHeight - offset,
|
|
);
|
|
};
|
|
|
|
window.addEventListener("scroll", handleScroll, { passive: true });
|
|
handleScroll();
|
|
|
|
return () => {
|
|
window.removeEventListener("scroll", handleScroll);
|
|
};
|
|
}, [offset]);
|
|
|
|
return isAtBottom;
|
|
}
|