Documentation Index
Fetch the complete documentation index at: https://react-docx.com/llms.txt
Use this file to discover all available pages before exploring further.
Auto-generated table of contents from document headings.
Props
| Prop | Type | Default | Description |
|---|
title | string | "Table of Contents" | TOC heading |
levels | number | 3 | Max heading level (1-6) |
showPageNumbers | boolean | true | Display page numbers |
hyperlinks | boolean | true | Make entries clickable |
className | string | — | Tailwind classes for title |
Basic usage
<Document>
<Section>
<TableOfContents />
</Section>
<Section>
<H1>Introduction</H1>
<Paragraph>...</Paragraph>
<H2>Background</H2>
<Paragraph>...</Paragraph>
<H1>Methods</H1>
<Paragraph>...</Paragraph>
</Section>
</Document>
Generates:
Table of Contents
Introduction .................. 1
Background .................. 1
Methods ....................... 2
Custom title
<TableOfContents title="Contents" />
<TableOfContents title="In This Document" />
No title:
<TableOfContents title="" />
Heading levels
Control how deep the TOC goes:
// Only H1
<TableOfContents levels={1} />
// H1 and H2
<TableOfContents levels={2} />
// H1, H2, and H3 (default)
<TableOfContents levels={3} />
// All levels
<TableOfContents levels={6} />
Page numbers
// With page numbers (default)
<TableOfContents showPageNumbers={true} />
// Without page numbers
<TableOfContents showPageNumbers={false} />
Hyperlinks
// Clickable entries (default)
<TableOfContents hyperlinks={true} />
// Plain text entries
<TableOfContents hyperlinks={false} />
Styling
Style the title:
<TableOfContents
title="Contents"
className="text-2xl font-bold text-blue-700"
/>
Full example
<Document>
{/* TOC on its own page */}
<Section>
<TableOfContents
title="Contents"
levels={3}
showPageNumbers={true}
hyperlinks={true}
className="text-xl font-bold"
/>
</Section>
{/* Document content */}
<Section>
<H1>Executive Summary</H1>
<Paragraph>...</Paragraph>
<H1>Introduction</H1>
<H2>Purpose</H2>
<Paragraph>...</Paragraph>
<H2>Scope</H2>
<Paragraph>...</Paragraph>
<H1>Analysis</H1>
<H2>Data Collection</H2>
<H3>Survey Results</H3>
<Paragraph>...</Paragraph>
<H3>Interview Findings</H3>
<Paragraph>...</Paragraph>
<H1>Conclusion</H1>
<Paragraph>...</Paragraph>
</Section>
</Document>
How it works
- Scans document for H1-H6 headings
- Filters by
levels prop
- Generates entries with indentation based on heading level
- Adds page numbers via Word’s PAGEREF field
- Creates hyperlinks to heading bookmarks
Headings automatically get bookmark IDs. No manual id props needed for TOC.
Updating the TOC
The TOC uses Word’s native field. To update page numbers after editing:
- In Word: Right-click TOC → “Update Field”
- Or: Ctrl+A, then F9