# useHeadings

Read a document's headings as entries for navigation.

```tsx
import { useHeadings } from "@zentara-co/zenos-ui";

const headings = useHeadings("article h2[id], article h3[id]", pathname);
// Each entry has { id, text, level: 2 | 3 }.
```

The hook returns an empty array during server rendering and before its first DOM read. It then observes matching headings for additions, removals, ID changes, and text changes. Existing heading IDs are preserved. Embedded copy buttons and hash-link controls are omitted from labels.

The shallowest matching heading level becomes level 2; deeper headings become level 3. Scope the selector to one article, and pass an optional route key when a persistent layout changes documents. The default selector is `h2[id], h3[id]`.

See [Table of Contents](/components/table-of-contents/#discover-headings) for a live example.

Source: https://zenos-ui.pages.dev/hooks/use-headings/