0.1.2 • Published 4 months ago

react-smooth-scrolll v0.1.2

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

react-smooth-scrolll

A lightweight and configurable smooth scrolling component for React and Next.js, powered by Lenis.

Features

  • Smooth scrolling with customizable speed and easing
  • Supports React and Next.js
  • Configurable props for scrolll behavior
  • Optimized for performance

Installation

npm install react-smooth-scrolll

or

yarn add react-smooth-scrolll

Usage

Basic Example

import { 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;

Customizing Scroll Behavior

You can override default settings using props:

<SmoothScroll scrollSpeed={2} smoothness={0.1} infinite={true} />

Available Props

PropTypeDefaultDescription
scrollSpeednumber1.5Adjusts wheel scroll sensitivity
infinitebooleanfalseEnables infinite scroll looping
smoothnessnumber0.07Linear interpolation (smoothness) intensity (between 0 and 1)
optionsobject{}Additional Lenis options

API

useSmoothScroll()

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>
    );
};

Testing

This package includes unit tests using Vitest and React Testing Library. Run tests with:

npm run test

License

MIT

0.1.2

4 months ago

0.1.1

4 months ago

0.1.0

4 months ago