Serialize markdown inside custom components
See original GitHub issueThe children
props inside custom components aren’t serialized. Let’s say that you have a Callout
component like the following:
import { Box, HStack } from "@chakra-ui/react";
import React, { FC } from "react";
const Callout: FC = ({ children }) => {
return (
<Box p={4} rounded="sm" bg="gray.800" color="white">
<HStack spacing={2}>
<Box fontSize={48}>💡</Box>
<Box>{children}</Box>
</HStack>
</Box>
);
};
export default Callout;
We call it like this:
<Callout>
Markdown oh **yeah**!! [Cool,
right?](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
</Callout>
You will get something like this:
This issue extends this one.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5
Top Results From Across the Web
Markdown with Custom Components in NextJS | DevLog 007
I thought of making a separate markdown file for the contents of the page, but then I realised that I could just map...
Read more >MDX and React - Docusaurus
Docusaurus has built-in support for MDX v1, which allows you to write JSX within your Markdown files and render them as React components....
Read more >Render Markdown With next-mdx-remote in our Next.js Page ...
[0:51] The next-mdx-remote has a function called serialize, which is exported from the next-mdx-remote/serialize. This function is quite easy, ...
Read more >next-mdx-remote - npm
Markdown in general is often paired with frontmatter, and normally this means adding some extra custom processing to the way markdown is handled ......
Read more >Component hydration with MDX in Next.js and Nx - | juri.dev
It basically is like JSX but allowing you to embed React components into a Markdown file. Generate a Youtube Component. Let's create a...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Afaik there is a stable release of mdx@2 coming soon, as soon as that is out we will put out a new release that supports it 😅
You could try using this fork which upgrades MDX to v2 - discussion here, which seems to handle nested markdown better in my experience.
It might work if your MDX becomes as follows, with new lines to force inline MDX transclusion:
Further discussions: https://github.com/mdx-js/mdx/issues/628 https://github.com/mdx-js/mdx/issues/241