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.
- 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
Create a table of contents:
Create a styled navigation menu:
Exclude specific headings from navigation:
Combine with scroll tracking to highlight active section:
- Documentation sites: Auto-generate table of contents
- Blog posts: Create article outlines
- Long-form content: Improve navigation
- Accessibility: Provide skip links
- 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