Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated with-mdx-remote dynamic components example #25366

Merged
merged 7 commits into from
Jun 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 11 additions & 2 deletions examples/with-mdx-remote/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 = [
Expand Down