Skip to content

Commit

Permalink
feat: add Lenis custom hook for smooth scrolling (#400)
Browse files Browse the repository at this point in the history
Co-authored-by: Sanchit Bajaj <[email protected]>
  • Loading branch information
TenzDelek and Sanchitbajaj02 authored Jul 29, 2024
1 parent 8bad028 commit caa525b
Show file tree
Hide file tree
Showing 5 changed files with 341 additions and 210 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"eslint-config-next": "13.4.13",
"framer-motion": "10.18.0",
"html-react-parser": "5.1.1",
"lenis": "^1.1.6",
"lucide-react": "0.316.0",
"next": "13.5.4",
"next-themes": "0.2.1",
Expand Down
3 changes: 3 additions & 0 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import AnimatedCursor from "react-animated-cursor";
import ScrollToTop from "@/components/ScrollToTop/scrolltotop";

import { Providers } from "./providers";
import LenisWrapper from "@/helper/leniswrapper";

const poppinsFont = Poppins({
subsets: ["latin"],
Expand Down Expand Up @@ -49,6 +50,7 @@ export const metadata: Metadata = {

export default async function RootLayout({ children }: { children: React.ReactNode }) {
return (
<LenisWrapper>
<html
lang="en"
className={`${poppinsFont.className} scrollbar-thin scrollbar-thumb-primary scrollbar-track-secondary-light scrollbar-track-rounded-full`}
Expand Down Expand Up @@ -90,5 +92,6 @@ export default async function RootLayout({ children }: { children: React.ReactNo
<ScrollToTop />
</body>
</html>
</LenisWrapper>
);
}
18 changes: 18 additions & 0 deletions src/helper/leniswrapper.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// src/components/LenisWrapper.tsx
'use client';

import React, { ReactNode } from 'react';
import useLenis from './useLenis';


interface LenisWrapperProps {
children: ReactNode;
}

const LenisWrapper: React.FC<LenisWrapperProps> = ({ children }) => {
useLenis();

return <>{children}</>;
};

export default LenisWrapper;
18 changes: 18 additions & 0 deletions src/helper/useLenis.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use client'
import { useEffect } from 'react';
import Lenis from 'lenis';

const useLenis = () => {
useEffect(() => {
const lenis = new Lenis();

function raf(time:any) {
lenis.raf(time);
requestAnimationFrame(raf);
}

requestAnimationFrame(raf);
}, []);
};

export default useLenis;
Loading

0 comments on commit caa525b

Please sign in to comment.