Skip to content

Snippets

Write text once in a snippet and use it on as many pages as you like.

Updated

A snippet is an MDX file in the snippets/ folder. Put it on a page with <Snippet>, and it shows there as if you had written it in place.

Hello, Ada. This line lives in snippets/hello.mdx.

That line comes from snippets/hello.mdx:

snippets/hello.mdx
Hello, {name}. This line lives in `snippets/hello.mdx`.

and the page includes it like this:

MDX
<Snippet file="hello.mdx" name="Ada" />

You can also import a snippet and use it as a component. Imports go after the frontmatter:

MDX
import Hello from '/snippets/hello.mdx';
<Hello name="Ada" />

Both forms work with the files in your docs folder’s snippets/ folder. A path that starts with / begins at the docs folder.

filestringpathrequired

The snippet’s file, as hello.mdx or /snippets/hello.mdx.

any other propstringpath

Each prop you add is a value the snippet reads by name in curly braces, as {name} above.

A snippet can include other snippets. It’s published on every page that includes it, and never on its own, so you don’t list it in docs.json.

Was this page helpful?

Report a problem

What’s the problem?

The docs team sees this. Other readers don’t.