Unverified Commit fbc0a0eb authored by Michael Novotny's avatar Michael Novotny Committed by GitHub

docs: Adds MDX Components file convention page and updates MDX page (#63568)

Co-authored-by: 's avatarLee Robinson <me@leerob.io>
Co-authored-by: 's avatarEthan Arrowood <ethan@arrowood.dev>
parent a5bb7c46
---
title: mdx-components.js
description: API reference for the mdx-components.js file.
related:
title: Learn more about MDX Components
links:
- app/building-your-application/configuring/mdx
---
The `mdx-components.js|tsx` file is **required** to use [`@next/mdx` with App Router](/docs/app/building-your-application/configuring/mdx) and will not work without it. Additionally, you can use it to [customize styles](/docs/app/building-your-application/configuring/mdx#using-custom-styles-and-components).
Use the file `mdx-components.tsx` (or `.js`) in the root of your project to define MDX Components. For example, at the same level as `pages` or `app`, or inside `src` if applicable.
```tsx filename="mdx-components.tsx" switcher
import type { MDXComponents } from 'mdx/types'
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
}
}
```
```js filename="mdx-components.js" switcher
export function useMDXComponents(components) {
return {
...components,
}
}
```
## Exports
### `useMDXComponents` function
The file must export a single function, either as a default export or named `useMDXComponents`.
```tsx filename="mdx-components.tsx" switcher
import type { MDXComponents } from 'mdx/types'
export function useMDXComponents(components: MDXComponents): MDXComponents {
return {
...components,
}
}
```
```js filename="mdx-components.js" switcher
export function useMDXComponents(components) {
return {
...components,
}
}
```
## Params
### `components`
When defining MDX Components, the export function accepts a single parameter, `components`. This parameter is an instance of `MDXComponents`.
- The key is the name of the HTML element to override.
- The value is the component to render instead.
> **Good to know**: Remember to pass all other components (i.e. `...components`) that do not have overrides.
## Version History
| Version | Changes |
| --------- | -------------------- |
| `v13.1.2` | MDX Components added |
--- ---
title: middleware.js title: middleware.js
description: API reference for the middleware.js file. description: API reference for the middleware.js file.
related: related:
title: Learn more about Middleware title: Learn more about Middleware
links: links:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment