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

0.0.0 • Public • Published

next-use-smooth-scroll

A simple smooth scroll react hook for Next.js

Install

pnpm add next-use-smooth-scroll

or

yarn add next-use-smooth-scroll

or

npm install next-use-smooth-scroll

Use Case

import { useSmoothScroll } from 'next-use-smooth-scroll'
import { useSearchParams } from 'next/navigation'
import Link from 'next/link'

const menuItems: MenuItem[] = [
  {
    href: '#Home',
  },
  {
    href: '#About',
  },
  {
    href: '#Activities',
  },
]

const activeHash = useSmoothScroll(
  menuItems.map(item => item.href),
  useSearchParams
)

return (
  <ul>
    {menuItems.map((item, index) => (
      <li key={index}>
        <Link href={item.href} scroll={false} className={`${activeHash === item.href ? 'active' : ''}`}>
          {item.text}
        </Link>
      </li>
    ))}
  </ul>
)

Package Sidebar

Install

npm i next-use-smooth-scroll

Weekly Downloads

4

Version

0.0.0

License

ISC

Unpacked Size

4.65 kB

Total Files

6

Last publish

Collaborators

  • liu_li