Skip to content
TrademarkTrademark
Docs
Hooks

useHeadingLinks

Updated: February 22, 2026
View on GitHub

The useHeadingLinks hook extracts all heading elements (h2-h6) from the current page and returns them as a structured array. This is useful for creating table of contents, navigation menus, or document outlines.

Used in components: HeadingNav

Most of the time you don't need to use this hook directly. The HeadingNav component already uses it internally to generate table of contents navigation. Use this hook when you need custom rendering or additional processing of page headings.

Features

  • Automatically finds all headings on the page
  • Extracts heading text, ID, and level
  • Filters out headings with data-exclude-nav attribute
  • Generates IDs for headings without them
  • Updates on mount

Basic usage

Create a table of contents:

With styling

Create a styled navigation menu:

Excluding headings

Exclude specific headings from navigation:

Return value

With active section tracking

Combine with scroll tracking to highlight active section:

Use cases

  • Documentation sites: Auto-generate table of contents
  • Blog posts: Create article outlines
  • Long-form content: Improve navigation
  • Accessibility: Provide skip links

Notes

  • Only runs once on mount (not reactive to DOM changes)
  • Headings without IDs get auto-generated IDs
  • Only includes h2-h6 (h1 is typically the page title)
  • Respects data-exclude-nav attribute
Edit this page on GitHub