● Zion Boggan
repos/Stepping App/apps/web/src/components/smooth-scroll.tsx
zionboggan.com ↗
24 lines · tsx
History for this file →
1
"use client";
2
 
3
import { useEffect, type ReactNode } from "react";
4
import Lenis from "lenis";
5
 
6
export function SmoothScroll({ children }: { children: ReactNode }) {
7
  useEffect(() => {
8
    if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
9
    const lenis = new Lenis({ duration: 1.1, smoothWheel: true });
10
    (window as unknown as { __lenis?: Lenis }).__lenis = lenis;
11
    let raf = 0;
12
    const loop = (t: number) => {
13
      lenis.raf(t);
14
      raf = requestAnimationFrame(loop);
15
    };
16
    raf = requestAnimationFrame(loop);
17
    return () => {
18
      cancelAnimationFrame(raf);
19
      lenis.destroy();
20
    };
21
  }, []);
22
 
23
  return <>{children}</>;
24
}