Unverified Commit 69b214bc authored by payapula's avatar payapula Committed by GitHub

Updated with-mdx-remote dynamic components example (#25366)

- Fixed the missing prop `components` to `<MDXRemote/>`.
- Added a `defaultComponents` and `source` mdx to provide more clarity on the example.

## Documentation / Examples

- [x] Make sure the linting passes
parent ed3e8f71
......@@ -34,10 +34,12 @@ For example, here's how you can change `getStaticProps` to pass a list of compon
```js
import dynamic from 'next/dynamic'
import Test from '../components/test'
const SomeHeavyComponent = dynamic(() => import('SomeHeavyComponent'))
// ...
const defaultComponents = { Test }
export function SomePage({ mdxSource, componentNames }) {
const components = {
...defaultComponents,
......@@ -46,10 +48,17 @@ export function SomePage({ mdxSource, componentNames }) {
: null,
}
return <MDXRemote {...mdxSource} />
return <MDXRemote {...mdxSource} components={components} />
}
export async function getStaticProps() {
const source = `---
title: Conditional custom components
---
Some **mdx** text, with a default component <Test name={title}/> and a Heavy component <SomeHeavyComponent />
`
const { content, data } = matter(source)
const componentNames = [
......
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