Skip to content

MDXProvider ignored when using @mdx-js/runtime #1879

Answered by godmar
godmar asked this question in Q&A
Discussion options

You must be logged in to vote

As per this comment it turns out that MDX and @mdx-js/runtime are deprecated (and apparently work differently in v2). The correct version is something like:

import React from 'react';
import * as runtime from 'react/jsx-runtime.js'
import * as provider from '@mdx-js/react'
import {evaluateSync} from '@mdx-js/mdx'
import { MDXProvider } from '@mdx-js/react';

const components = {
  Demo: props => <h1>This is a demo component from the provider</h1>
}

const mdx = `
# Hello, world!

<Demo />
`

export default () => {
  const {default: Content} = evaluateSync(mdx, {...provider, ...runtime})
  return (
    <MDXProvider components={components}>
      <Content />
    </MDXProvider>
  );
}

Source:

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by godmar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant