A lightweight and configurable smooth scrolling component for React and Next.js, powered by Lenis.
- Smooth scrolling with customizable speed and easing
- Supports React and Next.js
- Configurable props for scrolll behavior
- Optimized for performance
npm install react-smooth-scrolllor
yarn add react-smooth-scrolllimport { SmoothScroll } from "react-smooth-scrolll";
const App = () => {
    return (
        <SmoothScroll>
            <div style={{ height: "200vh", padding: "50px" }}>
                <h1>Welcome to Smooth Scrolling!</h1>
            </div>
        </SmoothScroll>
    );
};
export default App;- Create a folder utils/ScrollSmooth.tsxorproviders/SmoothScroll.tsx.
- Inside this file, paste the following code:
"use client";
import { SmoothScroll } from "react-smooth-scrolll";
const SmoothScrollProvider = ({ children }: { children: React.ReactNode }) => {
    return <SmoothScroll>{children}</SmoothScroll>;
};
export default SmoothScrollProvider;- Then, go to app/page.tsxand wrap your content:
import SmoothScrollProvider from "@/providers/SmoothScroll";
export default function Home() {
  return (
    <SmoothScrollProvider>
      <h1>Home Page!</h1>
    </SmoothScrollProvider>
  );
}You can override default settings using props:
<SmoothScroll scrollSpeed={2} smoothness={0.1} infinite={true} />| Prop | Type | Default | Description | 
|---|---|---|---|
| scrollSpeed | number | 1.5 | Adjusts wheel scroll sensitivity | 
| infinite | boolean | false | Enables infinite scroll looping | 
| smoothness | number | 0.07 | Linear interpolation (smoothness) intensity (between 0 and 1) | 
| options | object | {} | Additional Lenis options | 
A custom hook to access the Lenis instance for advanced controls.
import { useSmoothScroll } from "react-smooth-scrolll";
const Component = () => {
    const lenis = useSmoothScroll();
    return (
        <button onClick={() => lenis?.scrollTo(500)}>
            Scroll to 500px
        </button>
    );
};This package includes unit tests using Vitest and React Testing Library. Run tests with:
npm run testMIT