useScrollSpy

Highlight the heading that is visible while the page is scrolled, for a table of contents.

This is custom React hooks, you need to follow the Basic Rules when you use it.

General

Lists the h2 headings of the page and marks the one being read.

APIs

useScrollSpy

const useScrollSpy = (options?: {
  selector?: string
  offset?: number
}) => {
  active: number
  data: {
    id: string
    label: string
    depth: number
    element: HTMLElement
  }[]
  reinitialize: () => void
}
Edit this page on GitHub