| "use client"; | |
| import { useEffect, useRef } from "react"; | |
| import Lenis from "lenis"; | |
| export function SmoothScrollProvider({ | |
| children, | |
| }: { | |
| children: React.ReactNode; | |
| }) { | |
| const lenisRef = useRef<Lenis | null>(null); | |
| useEffect(() => { | |
| const lenis = new Lenis({ | |
| duration: 1.2, | |
| easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), | |
| touchMultiplier: 2, | |
| infinite: false, | |
| }); | |
| lenisRef.current = lenis; | |
| function raf(time: number) { | |
| lenis.raf(time); | |
| requestAnimationFrame(raf); | |
| } | |
| requestAnimationFrame(raf); | |
| return () => { | |
| lenis.destroy(); | |
| lenisRef.current = null; | |
| }; | |
| }, []); | |
| return <>{children}</>; | |
| } | |