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
With styling
Excluding headings
Return value
With active section tracking
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