Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

664 B
Raw Blame
import { useState, useEffect } from "react";

const useDetectPageBottom = () => {
  const [reachedBottom, setReachedBottom] = useState<boolean>(false);

  useEffect(() => {
    const handleScroll = () => {
      const totalHeight = document.documentElement.scrollHeight;
      const scrolledHeight = window.scrollY + window.innerHeight;

      if (scrolledHeight >= totalHeight) {
        setReachedBottom(true);
      }
    };

    window.addEventListener("scroll", handleScroll);

    return () => {
      window.removeEventListener("scroll", handleScroll);
    };
  }, []);

  return { reachedBottom, setReachedBottom };
};

export default useDetectPageBottom;