How can I improve my setup? (currently doing client side rendering when I know there's a better way) #2202
-
Current packages: I have a personal site and here's the folder structure, stored locally on GitHub within the project, that I like: I like to import my mdx content as a component and show it inside by js pages, like in // [slug].js
export default function Note({ metadata }) {
const { title, date, tags, lastmod, type, slug } = metadata;
return (
<>
<h1>{title}</h1>
<MdxRenderer type={type} slug={slug} />
</>
);
} //components/MdxRenderer.js
// Client side rendering of the mdx file. TODO: Find a way to do this with pre-render
export default function MdxRenderer({ type, slug }) {
const [mdxModule, setMdxModule] = useState();
useEffect(() => {
(async () => {
const module = await import(`../content/${type}/${slug}/index.mdx`);
setMdxModule(module);
})();
}, []);
const Content = mdxModule ? mdxModule.default : Fragment;
return <Content />;
} See, the problem is that I'm client side rendering b/c I'm compiling the MDX file in TLDR; --- Extra |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Did you see this guide?: https://mdxjs.com/guides/mdx-on-demand/ For the first problem, hooks, in Next.js: perhaps you can do this without a hook: these Second, webpack modules, indeed: if you have MDX files that have further imports, we don‘t bundle those for you. This project only compiles MDX files to JS. It doesn’t bundle further files. Third, on the react provider: you likely don’t need providers. They probably only make things slower. You can pass components. https://mdxjs.com/docs/using-mdx/#mdx-provider |
Beta Was this translation helpful? Give feedback.
Did you see this guide?: https://mdxjs.com/guides/mdx-on-demand/
For the first problem, hooks, in Next.js: perhaps you can do this without a hook: these
getStaticProps
things from Next.js can run async things.Second, webpack modules, indeed: if you have MDX files that have further imports, we don‘t bundle those for you. This project only compiles MDX files to JS. It doesn’t bundle further files.
Third, on the react provider: you likely don’t need providers. They probably only make things slower. You can pass components. https://mdxjs.com/docs/using-mdx/#mdx-provider