I want to convert code returned by bundleMDX
to string for RSS reader I'm writing so I can use it with ReactDOMServer.renderToStaticMarkup(mdx)
like:
The Tailwind Blog above uses next-mdx-remote
where it works but I'm not sure how to do the similar thing in mdx-bundler
.
I've tried wrapping code in MDXLayoutRenderer
using mdxSource
:
import { MDXProvider } from '@mdx-js/react'
export const MDXLayoutRenderer = ({ mdxSource, ...rest }: IMDXLayoutRenderer): JSX.Element => {
const MDXLayout = React.useMemo(() => getMDXComponent(mdxSource), [mdxSource])
return <MDXLayout components={MDXComponents as any} {...rest} />
}
.
.
.
const mdx = (
<MDXProvider>
<MDXLayoutRenderer mdxSource={code} />
</MDXProvider>
)
But this throws weird TS errors like:
'MDXProvider' refers to a value, but is being used as a type here. Did you mean 'typeof MDXProvider'?ts(2749)
If I make mdx
a function & return the value from it, then also it doesn't work:
const mdx = () => (
<MDXProvider>
<MDXLayoutRenderer mdxSource={code} />
</MDXProvider>
)
All I need is to pass a html
formatted string so that I can send it to RSS package feed.
My example is exactly similar to the Tailwind Blog with 1 difference: I'm using mdx-bundler
instead of next-mdx-remote
How can I solve this problem?