How to transform a markdown string to be used in a React component #2024
-
|
Hi, I'm having a string, let's say it's const copyrightText = '© 2022 [John Doe](https://example.com)';and I want to use this in a React component so that it's rendered to a working link like this: <footer>
<SomeComponentThatTakesMdString content={copyrightText} />
<div>...</div>
</footer>How can I use MDX to create that I know that I can use Remark or @mdx-js/runtime, but @mdx-js/runtime says this is not the preferred way to use MDX. I'm wondering if there is a better way? The reason that I want to use only MDX without another lib is because I'm already using MDX in other parts of the web and I don't want to unnecessarily install another lib. The docs I read is about taking the whole MDX file to render, but I just want to render only a string in my case. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Beta Was this translation helpful? Give feedback.
@mdx-js/runtimeis old, you can useevaluatefrom@mdx-js/mdx2, this is documented in several places including the getting started docs