question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Serialize markdown inside custom components

See original GitHub issue

The 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: Screenshot 2021-10-13 at 1 52 57 AM

This issue extends this one.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
jescalancommented, Oct 13, 2021

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 😅

2reactions
mattbooncommented, Oct 12, 2021

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:

<Callout>

Markdown oh **yeah**!! [Cool,
right?](https://www.youtube.com/watch?v=dQw4w9WgXcQ)
  
</Callout>

Further discussions: https://github.com/mdx-js/mdx/issues/628 https://github.com/mdx-js/mdx/issues/241

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found