Skip to main content
One of the core principles of software development is DRY (Don’t Repeat Yourself). This applies to documentation too. If you find yourself repeating the same content across multiple pages, create a reusable snippet to keep everything in sync.

Creating a snippet

Pre-condition: Snippet files must live in the snippets directory.
Files in the snippets directory are treated as components, not standalone pages. To render a snippet as a page, import it into an MDX file outside of snippets.

Default export

  1. Create a snippet with the content you want to reuse. You can accept props as variables.
snippets/my-snippet.mdx
Snippet files must be inside the snippets directory for imports to resolve.
  1. Import and use the snippet in any page:
destination-file.mdx

Reusable variables

  1. Export variables from a snippet:
snippets/variables.mdx
  1. Import and use them:
destination-file.mdx

Reusable components

  1. Export a component as an arrow function:
snippets/custom-component.mdx
MDX does not compile inside arrow function bodies. Use HTML syntax within exported components.
  1. Import and use it:
destination-file.mdx