One of the core principles in technical writing is DRY (Don’t Repeat Yourself). Mintlify enables you to define custom snippets in dedicated files that can be reused across multiple pages.

Creating a Snippet

Pre-requisite: You must create your snippet in a file with an underscore (_) prefix. Create a file (e.g., _snippets/my-snippet.mdx) and write your reusable content inside it.
_snippets/my-snippet.mdx
You can write MDX content, including components, and they will render when imported.

Importing a Snippet

Import the snippet using this import syntax:
import MySnippet from '/snippets/my-snippet.mdx';
Then use it like a React component:
<MySnippet />

Snippet Variables

Snippets can receive props and render dynamic content.
_snippets/custom-snippet.mdx
export const MySnippet = ({ title, children }) => (
  <div>
    <h2>{title}</h2>
    {children}
  </div>
);
Import and use with props:
import { MySnippet } from '/snippets/custom-snippet.mdx';

<MySnippet title="Hello world">
  This is the body.
</MySnippet>