Replies: 1 comment
-
Hi @Jervx , no need to add any feature into next-mdx-remote for that. I suggest you to use a recma plugin called recma-mdx-escape-missing-components which is one of my plugins. It escapes missing components with empty, no fallback component (I consider no need a fallback). // ...
import recmaMdxEscapeMissingComponents from "recma-mdx-escape-missing-components";
// ...
const parseContent = useCallback(async () => {
try {
const mdxContent = await serialize(markdown, {
mdxOptions: {
development: process.env.NODE_ENV === "development",
rehypePlugins: [rehypePrism],
recmaPlugins: [recmaMdxEscapeMissingComponents],
},
});
setMdxData(mdxContent);
} catch (e) {}
}, [markdown]);
// ... I wonder your feedback :) |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I created a custom hook useSerializeMd that will serialize whatever string you provide it.
// useSerializeMd.tsx
// chat-fragment.tsx
The message contain this string 👉🏼
Hello <MyCustom>
I forgot to provide the MyCustom component to the components props of
<MDXRemote components={...} />
, by default it'll crash.I was wondering if there's a way to add an optional fallback component in case we forgot to provide it to the MDXRemote?
Or alternatively make MDXRemote skip that missing component instead of crashing?
I came across to this lightweight library called markdown-to-jsx, it also support custom component. In case the markdown contains a custom component like
but the component was not provided to the
<Markdown />
component, it does skips that missing custom component and proceed rendering the markdown without crashing the app.By the way I am using
Next.js 14
.Beta Was this translation helpful? Give feedback.
All reactions