1.2.0 • Published 2 years ago

use-scrollspy v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

use-scrollspy

Configurable scrollspy react hook for pairing anchor links with page sections.

🤔 What is it?

The idea is to have a simple and easy to use hook that lets you pair page sections with links, to display which section is currently active.

Check out my personal website to see the hook in action.

📦 Installation

npm i use-scrollspy

# with yarn
yarn add use-scrollspy

🚀 Usage

import { useScrollspy } from 'use-scrollspy'

useScrollspy({
  ids: ['intro', 'projects', 'about', 'contact'], // ids of the sections to watch
  hrefs: ['/#intro', '/#projects', '/#about', '/#contact'], // hrefs of the links to activate when section is active
  offset: 'topCenter', // offset for when the section should be considered active
  activeClass: 'active-nav-link', // class to apply to links when their section is active
})

📝 Example

More examples will be added in the near future

Check out my personal website to see the hook in action. The code can be found here.

🛣️ Roadmap

  • Publish to NPM
  • Add more examples
  • Add more offset options
  • Add possibility to use refs instead of ids