Skip to content

Commit

Permalink
Fix default export guide
Browse files Browse the repository at this point in the history
The given code example did not use the default export correctly
  • Loading branch information
delucis committed Jul 30, 2022
1 parent edb40b5 commit a24d8fc
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/pages/en/migrate.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,25 @@ If you're not familiar with MDX, here are some steps you can follow to quickly c
The object returned when importing `.mdx` files (including using Astro.glob) differs from the object returned when importing `.md` files. However, `frontmatter`, `file`, and `url` work identically.
:::

Additionally, after importing `.mdx`, you can use the default export as a component:
5. Update any use of the `<Content />` component to use the default export when importing MDX:

```astro title="example.astro"
---
const mdxPosts = await Astro.glob('../pages/posts/*.mdx');
---
```astro title="src/pages/index.astro"
---
// Multiple imports with Astro.glob
const mdxPosts = await Astro.glob('./posts/*.mdx');
---
{mdxPosts.map(Post => <Post/>)}
```
{mdxPosts.map(Post => <Post.default />)}
```

```astro title="src/pages/index.astro"
---
// Import a single page
import { default as About } from './about.mdx';
---
<About />
```

:::tip
While you are transitioning to MDX, you may wish to [enable the legacy flag](/en/reference/configuration-reference/#legacyastroflavoredmarkdown) and include both **`.md` and `.mdx`** files, so that your site continues to function normally even before all your files have been converted. Here is one way you can do that:
Expand Down

0 comments on commit a24d8fc

Please sign in to comment.