Reusable Snippets
Reusable, custom snippets to keep content in sync
One of the core principles of software development is DRY (Don’t Repeat Yourself), which applies to documentation as well. If you find yourself repeating the same content in multiple places, you should create a custom snippet to keep your content in sync.
Creating a custom snippet
Pre-condition: You must create your snippet file in the snippets
directory in order for the import to work.
Any page in the snippets
directory will be treated as a snippet and will not
be rendered into a standalone page. If you want to create a standalone page
from the snippet, import the snippet into another file and call it as a
component.
Default export
- Add content to your snippet file that you want to re-use. Optionally, you can add variables that can be filled in via props when you import the snippet. In this example, our variable is word.
- Import the snippet into your destination file.
Exporting with variables
- Optionally, you can add variables that can be filled in via props when you import the snippet. In this example, our variable is word.
- Import the snippet into your destination file with the variable. The property will fill in based on your specification.
Reusable variables
- Export a variable from your snippet file:
- Import the snippet from your destination file and use the variable:
Reusable components
- Inside your snippet file, create a component that takes in props by exporting your component in the form of an arrow function.
MDX does not compile inside the body of an arrow function. Stick to HTML syntax when you can or use a default export if you need to use MDX.
- Import the snippet into your destination file and pass in the props
Client-Side Content
By default, Mintlify employs server-side rendering, generating content
at build time. For client-side content loading, ensure to verify the
document
object’s availability before initiating the rendering process.
Was this page helpful?