Skip to content

Working around the removal of layoutProps #1896

Answered by juice49
juice49 asked this question in Q&A
Discussion options

You must be logged in to vote

I think I've stumbled upon an interesting work around. MDX documents can export a getStaticProps function just like any other Next.js page. Page props can be used in a similar way to layoutProps in MDX 1. We can add a getStaticProps function to the MDX document that returns values we want to expose as Next.js page props.

To make this smoother, I created a function to modify the AST and automatically add a getStaticProps function based on a mapping provided by the user. This means:

  • MDX documents can still export values that we can import directly.
  • These exports can also be exposed to Next.js (e.g. in the pageProps prop passed to _app.tsx).

Here's my first attempt. 🚨 Not fully tested; jus…

Replies: 2 comments 5 replies

Comment options

You must be logged in to vote
3 replies
@juice49
Comment options

@wooorm
Comment options

@juice49
Comment options

Comment options

You must be logged in to vote
2 replies
@wooorm
Comment options

@juice49
Comment options

Answer selected by juice49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants