Skip to content

Instantly share code, notes, and snippets.

@pomber
Last active October 6, 2021 17:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pomber/758a649aa8ef2a2a353a0da9c7d5e951 to your computer and use it in GitHub Desktop.
Save pomber/758a649aa8ef2a2a353a0da9c7d5e951 to your computer and use it in GitHub Desktop.
import { bundleMDX } from "mdx-bundler";
import { getMDXComponent } from "mdx-bundler/client";
import React from "react";
export async function getServerSideProps() {
const mdxSource = `
# Hello
~~~js
console.log(1);
~~~`;
const mdxBundle = await bundleMDX(mdxSource);
return { props: { mdxBundle } };
}
export default function Foo({ mdxBundle }) {
const Component = getMDXComponent(mdxBundle.code);
return <Component />;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment