What is the recommended way to load MDX in NextJS's getStaticProps? (can't get it to work) #1866
-
Hi 👋 . I am having a bit of a crisis of confidence, because I can't seem to figure out how to do what seems like it should be a straight-forward use-case 🙈 I suspect I'm missing something obvious and somebody here will be able to point out just what an idiot I am 🤞 Question What is the recommended way to dynamically load MDX at build-time inside NextJS's 'getStaticProps` method? (aka: at build time) Background
In Gatsby, I can load the files from disk at the build step, and programmatically create pages for them. Sweet. useStaticProps and the mdx react loader The props one returns from there need to be something that can be serialized into JSON. just import that stuff Can't import because due to the language and the dynamic route, the path tot he file is dynamic. do the reading from disk myself and then compile them to something There's so many do not do this warnings in the docs, that I sort of feel like I should not do this. TL:DR What is the recommended way to dynamically load MDX at build-time inside NextJS's 'getStaticProps` method? The NextJS examples all assume that the MDX files are the pages of the NextJS site. Thank you and forgive my ignorance. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To those who came here looking for answers, this page shows how it's done: https://mdxjs.com/guides/mdx-on-demand/ (thanks to @wooorm for pointing me in the right direction) |
Beta Was this translation helpful? Give feedback.
To those who came here looking for answers, this page shows how it's done: https://mdxjs.com/guides/mdx-on-demand/
(thanks to @wooorm for pointing me in the right direction)