use-smooth-scroll-to
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

use-smooth-scroll-to

React hook for smooth scrolling

License NPM Version Known Vulnerabilities NPM Downloads

Install

# npm
npm i use-smooth-scroll-to
# yarn
yarn add use-smooth-scroll-to
# pnpm
pnpm i use-smooth-scroll-to

Usage

import { useRef } from "react";
import { useScroll } from "use-smooth-scroll-to";

function App() {
    const { scroll } = useScroll({ easing: "easeInCirc" });
    const divRef = useRef(null);

    return (
        <div>
            <button
                onClick={() => {
                    scroll(divRef.current);
                }}
            >
                Go to hello world
            </button>
            <div style={{ height: "100vh" }} />
            <div ref={divRef}>HELLO WORLD</div>
            <button
                onClick={() => {
                    scroll(0);
                }}
            >
                Go to top
            </button>
        </div>
    );
}

export default App;

Props

Property Type required Description
useNativeScroll boolean false Use window.scrollTo for scrolling
easing ((x: number) => number) | string false Your own easing function or name of implemented easing functions

List of easing functions

  • linear
  • easeInSine
  • easeInCubic
  • easeInQuint
  • easeInCirc
  • easeOutSine
  • easeOutCubic
  • easeOutQuint
  • easeOutCirc
  • easeInOutSine
  • easeInOutCubic
  • easeInOutQuint
  • easeInOutCirc

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
0.1.00latest

Version History

VersionDownloads (Last 7 Days)Published
0.1.00

Package Sidebar

Install

npm i use-smooth-scroll-to

Weekly Downloads

0

Version

0.1.0

License

MIT

Unpacked Size

7.64 kB

Total Files

12

Last publish

Collaborators

  • marshallku