Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import { useEffect } from "react";
import Lenis from "lenis";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import Navbar from "./components/Navbar";
import Footer from "./components/Footer";
Expand All @@ -9,7 +10,36 @@ import Contributors from "./pages/Contributors";
import CommunityPage from "./pages/CommunityPage";
import BackToTop from "./components/shared/BackToTop";

/**
* Top-level application component that configures routing, global layout, and smooth scrolling.
*
* Initializes a Lenis instance on mount to enable smooth scrolling (driven by a requestAnimationFrame loop) and destroys it on unmount.
*
* @returns {JSX.Element} The root React element containing the Router, layout (Navbar, Routes, Footer), and BackToTop component.
*/
export default function App() {
useEffect(() => {
// Initialize Lenis for smooth scroll
const lenis = new Lenis({
duration: 0.8, // scroll speed (1.2s for smooth flow)
easing: (t) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // default easing
smooth: true,
smoothTouch: false, // disable smooth on mobile for performance
});

// RAF loop
const raf = (time) => {
lenis.raf(time);
requestAnimationFrame(raf);
};
requestAnimationFrame(raf);

// Cleanup when component unmounts
return () => {
lenis.destroy();
};
}, []);

return (
<Router>
<div className="min-h-screen flex flex-col bg-gradient-to-br from-gray-100 to-indigo-50 dark:from-gray-900 dark:to-gray-800">
Expand All @@ -33,4 +63,4 @@ export default function App() {
</div>
</Router>
);
}
}