Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ export async function getStaticProps() {
Custom components from <code>MDXProvider</code><a id="mdx-provider"></a>
</summary>

If you want to make components available to any `<MDXRemote />` being rendered in your application, you can use [`<MDXProvider />`](https://mdxjs.com/docs/using-mdx/#mdx-provider) from `@mdx-js/react`.
If you want to make components available to any `<MDXRemote />` being rendered in your application, you can use [`<MDXProvider />`](https://mdxjs.com/docs/using-mdx/#mdx-provider) directly from `next-mdx-remote`.

```jsx
// pages/_app.jsx
import { MDXProvider } from '@mdx-js/react'
import { MDXProvider } from 'next-mdx-remote'

import Test from '../components/test'

Expand Down Expand Up @@ -305,7 +305,7 @@ This library exposes a function and a component, `serialize` and `<MDXRemote />`
mdxOptions: {
remarkPlugins: [],
rehypePlugins: [],
format: 'mdx'
format: 'mdx',
},
// Indicates whether or not to parse the frontmatter from the mdx source
parseFrontmatter: false,
Expand Down Expand Up @@ -407,13 +407,12 @@ export default function ExamplePage({ mdxSource }: Props) {
)
}

export const getStaticProps: GetStaticProps<{mdxSource: MDXRemoteSerializeResult}> =
async () => {
const mdxSource = await serialize(
'some *mdx* content: <ExampleComponent />'
)
return { props: { mdxSource } }
}
export const getStaticProps: GetStaticProps<{
mdxSource: MDXRemoteSerializeResult
}> = async () => {
const mdxSource = await serialize('some *mdx* content: <ExampleComponent />')
return { props: { mdxSource } }
}
```

## Migrating from v2 to v3
Expand Down
6 changes: 3 additions & 3 deletions __tests__/serialize.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import ReactDOMServer from 'react-dom/server'
import { paragraphCustomAlerts } from '@hashicorp/remark-plugins'
import * as MDX from '@mdx-js/react'

import { MDXRemote } from '../src/index'
import { MDXRemote, MDXProvider } from '../src/index'
import { serialize } from '../src/serialize'
import { renderStatic } from '../.jest/utils'

Expand Down Expand Up @@ -74,13 +74,13 @@ describe('serialize', () => {
const mdxSource = await serialize('<Test />')

const result = ReactDOMServer.renderToStaticMarkup(
<MDX.MDXProvider
<MDXProvider
components={{
Test: () => <p>Hello world</p>,
}}
>
<MDXRemote {...mdxSource} />
</MDX.MDXProvider>
</MDXProvider>
)

expect(result).toMatchInlineSnapshot(`"<p>Hello world</p>"`)
Expand Down
6 changes: 4 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export type MDXRemoteProps = MDXRemoteSerializeResult & {

export { MDXRemoteSerializeResult }

export const MDXProvider = mdx.MDXProvider

/**
* Renders compiled source from next-mdx-remote/serialize.
*/
Expand Down Expand Up @@ -101,9 +103,9 @@ export function MDXRemote({
// wrapping the content with MDXProvider will allow us to customize the standard
// markdown components (such as "h1" or "a") with the "components" object
const content = (
<mdx.MDXProvider components={components}>
<MDXProvider components={components}>
<Content />
</mdx.MDXProvider>
</MDXProvider>
)

// If lazy = true, we need to render a wrapping div to preserve the same markup structure that was SSR'd
Expand Down