"use client"; import { useEffect, useState } from "react"; export default function ProgressWrap() { const [scrolled, setScrolled] = useState(0); const [scrollHeight, setScrollHeight] = useState(500); const scrollToTop = () => { window.scrollTo({ top: 0, behavior: "smooth", // You can use 'auto' or 'instant' as well }); }; const handleScroll = () => { if (document.querySelector("#scroll-top")) { const currentScroll = document.body.scrollTop || document.documentElement.scrollTop; setScrolled(currentScroll); if (currentScroll >= 150) { document.querySelector("#scroll-top").classList.add("active-progress"); } else { document .querySelector("#scroll-top") .classList.remove("active-progress"); } const totalScrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight; setScrollHeight(totalScrollHeight); } }; useEffect(() => { window.addEventListener("scroll", handleScroll); return () => { window.removeEventListener("scroll", handleScroll); }; }, []); return ( <>