diff --git a/app/layout.tsx b/app/layout.tsx index 8abdb9f..8c37c80 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -6,6 +6,8 @@ import LightRays from "../components/LightRays"; import Navbar from "../components/Navbar"; import { PostHogProvider } from "./providers"; import { Toaster } from "sonner"; +import BackToTop from '../components/BackToTop'; + const SchibstedGrotesk = Schibsted_Grotesk({ variable: "--font-schibsted-grotesk", @@ -56,10 +58,10 @@ export default function RootLayout({
{children}
+ ); -} - +} \ No newline at end of file diff --git a/components/BackToTop.tsx b/components/BackToTop.tsx new file mode 100644 index 0000000..533f944 --- /dev/null +++ b/components/BackToTop.tsx @@ -0,0 +1,51 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { ArrowUp } from "lucide-react"; + +export default function BackToTop() { + const [visible, setVisible] = useState(false); + + useEffect(() => { + const handleScroll = () => { + setVisible(window.scrollY > 200); + }; + + window.addEventListener("scroll", handleScroll); + handleScroll(); // ✅ Fix for mount visibility + + return () => { + window.removeEventListener("scroll", handleScroll); + }; + }, []); + + const scrollToTop = () => { + window.scrollTo({ + top: 0, + behavior: "smooth", + }); + }; + + if (!visible) return null; + + return ( + + ); +}