Reusable Snippets
Create reusable Markdown text and React component snippets once, insert them across pages, and keep shared documentation synchronized through the web or code editor.
Snippet types
| Type | Extension | Created from | Contains |
|---|---|---|---|
| Markdown | .md or .mdx | Web editor or code editor | Text, headings, code blocks, MDX components |
| React component | .jsx | Web editor or code editor | React component with named exports |
How snippets work
Snippets are repository files stored in the top-level snippets/ directory. Documentation.AI supports Markdown snippets in .md and .mdx files, plus React component snippets in .jsx files. The editor inserts a reference to the source file rather than copying its content into the page.
Key behaviors:
- Pages store a file path reference, not a copy of the content.
- Each snippet renders as an atomic, non-editable block with a live preview.
- Editing the source file updates every page that imports the snippet after the next render or deployment.
- Snippets support nesting up to 5 levels deep.
Create a snippet
From the web editor
Use the Snippet slash command to create a new snippet.
Open the snippet picker
Open an editable MDX page, type /, and select Snippet from the command list.
Start a new snippet
Select Create new snippet in the picker dialog.
Choose the snippet details
Enter a name, choose Markdown or React Component, and add an optional description for a React component.
Documentation.AI converts the name to kebab-case and creates the file under snippets/. Markdown snippets use the .mdx extension. React components use .jsx.
Create and edit the file
Select Create & Open. Documentation.AI creates the file and opens it in the editor.
Your new source file is now available to insert into pages through the snippet picker.
From the code editor
Create a file directly under the top-level snippets/ directory. Use .md or .mdx for Markdown and MDX content, or .jsx for a React component.
For example:
snippets/
├── api-authentication.mdx
└── status-card.jsx
The filename determines the component name the editor displays. The file path is the source of truth for every page that imports the snippet.
Insert a snippet into a page
In the web editor
Insert an existing snippet with the Snippet slash command.
Open the snippet picker
Open an editable MDX page, type /, and select Snippet.
Find the source file
Search the picker for a snippet by name. The picker searches recursively below the snippets/ directory and lists .md, .mdx, and .jsx files.
Insert the snippet
Select the snippet to add it to the page. The editor inserts an atomic reference and displays a live preview of the source content.
The pencil button on the snippet block opens the source file for editing.
In the code editor
Import a snippet with a default import and render the generated component name as a self-closing element.
import ApiAuthentication from "/snippets/api-authentication.mdx"
<ApiAuthentication />
import StatusCard from "/snippets/status-card.jsx"
<StatusCard />
The import path must point to a file under snippets/. Documentation.AI recognizes default imports as visible snippet references. Named imports remain ordinary ESM and are not converted into snippet blocks by the editor.
MDX snippets
MDX snippets contain Markdown or MDX content, including text, headings, code blocks, and Documentation.AI components.
The editor removes frontmatter from the live preview, but the source file can still use frontmatter. A newly created Markdown snippet starts with:
---
title: api-authentication
---
Add the reusable content below the frontmatter:
---
title: api-authentication
---
Authenticate requests with an API key in the `Authorization` header.
<Callout kind="info">
Keep API keys out of client-side code and public repositories.
</Callout>
When you insert the snippet, the page renders the body content and supported MDX components. The snippet's frontmatter does not appear inside the importing page.
React component snippets
React component snippets are stored in .jsx files. Documentation.AI compiles them in the browser and renders the component in the snippet preview. React hooks, component state, and browser APIs are supported.
A React component snippet must use named exports only. The component name should match the filename-derived component name. For example, status-card.jsx should contain:
export const description = "Displays the current publishing status"
export const StatusCard = () => {
return (
<div className="my-6 rounded-lg border p-4">
<strong>Publishing status</strong>
<p>Your documentation is ready to publish.</p>
</div>
)
}
The optional description export provides searchable metadata. It does not affect the rendered component.
React component snippets must follow three rules:
- No third-party npm packages. The snippet runtime only provides React. Any import from an external package fails at compile time.
- No import statements. Do not include
importlines in a.jsxsnippet. The platform replaces any imports during compilation and uses only the named exports from the file. React hooks and browser APIs are available without importing them. - Named exports only. Use
export const ComponentName = () => {...}orexport function ComponentName() {...}. Default exports are not supported for React components or MDX components.
The editor reports syntax, missing-component, and runtime errors in the snippet preview. Keep the component self-contained because the snippet node does not currently provide a props editor or pass attributes from the importing page.
Anti-patterns
Avoid these common mistakes when writing React component snippets.
Manage snippets
Edit the source file to update a reusable snippet. Pages that import the snippet render the updated source, so one change keeps every occurrence aligned.
Removing a snippet from a page deletes only that occurrence. The source file remains in snippets/, and other pages that use the same snippet are unchanged.
If a source file is renamed, moved, or deleted, its existing reference remains on the page and displays Unable to load snippet. The edit control is disabled until the source file is available again, but you can remove the broken reference from the page.
Deployment and search
Documentation.AI validates snippets during deployment and deploys each snippet as an independent file. MDX snippet content is expanded into importing pages during search indexing, so reusable prose and headings can be found through documentation search.
Write a useful description for React component snippets and clear content for MDX snippets. MDX body content is indexed with importing pages, while a React component snippet's description is used as its searchable text.
Snippet imports inside code blocks are treated as example code. Documentation.AI does not expand those imports during search indexing, so you can safely show import syntax in a code sample.