2023-06-14 17:34:54 -05:00
|
|
|
import { useState, useEffect } from "react";
|
|
|
|
|
|
|
|
const useDetectPageBottom = () => {
|
|
|
|
const [reachedBottom, setReachedBottom] = useState<boolean>(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
const handleScroll = () => {
|
2023-10-03 06:04:13 -05:00
|
|
|
const totalHeight = document.documentElement.scrollHeight;
|
|
|
|
const scrolledHeight = window.scrollY + window.innerHeight;
|
2023-06-14 17:34:54 -05:00
|
|
|
|
2023-10-03 06:04:13 -05:00
|
|
|
if (scrolledHeight >= totalHeight) {
|
|
|
|
setReachedBottom(true);
|
|
|
|
}
|
2023-06-14 17:34:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
window.addEventListener("scroll", handleScroll);
|
|
|
|
|
2023-10-03 06:04:13 -05:00
|
|
|
return () => {
|
|
|
|
window.removeEventListener("scroll", handleScroll);
|
|
|
|
};
|
2023-06-14 17:34:54 -05:00
|
|
|
}, []);
|
|
|
|
|
2023-10-03 06:04:13 -05:00
|
|
|
return { reachedBottom, setReachedBottom };
|
2023-06-14 17:34:54 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
export default useDetectPageBottom;
|