Skip to content
New issue

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

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

Already on GitHub? # to your account

MDX runtime #558

Closed
subhero24 opened this issue Apr 29, 2019 · 3 comments
Closed

MDX runtime #558

subhero24 opened this issue Apr 29, 2019 · 3 comments

Comments

@subhero24
Copy link

I have a question regarding using MDX runtime.
I want to use MDX at runtime to parse MDX to react elements.

The docs contain the following example

import React from 'react'
import MDX from '@mdx-js/runtime'
// Provide custom components for markdown elements
const components = {
  h1: props => <h1 style={{ color: 'tomato' }} {...props} />
}
// Provide custom components that will be referenced as JSX
// in the markdown string
const scope = {
  Demo: props => <h1>This is a demo component</h1>
}
const mdx = `
# Hello, world!
<Demo />
`
export default () => (
  <MDX components={components} scope={scope}>{mdx}</MDX>
)

Using this component results in an error message:

Component Demo was not imported, exported, or provided by MDXProvider as global scope

Is the example still correct? Do I need to always wrap it with an MDXProvider?

@johno
Copy link
Member

johno commented Apr 29, 2019

Ah, nice catch. We should most likely update the docs so that they pass Demo in with components since that's what's passed to the MDXProvider. As of v1, scope is more intended for other variables rather than additional components.

@subhero24
Copy link
Author

Putting Demo in the components object does indeed work. Thanks!

@johno
Copy link
Member

johno commented May 1, 2019

The readme has been updated so I'm going to go ahead and close now, thanks for opening!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Development

No branches or pull requests

2 participants