Skip to content

Pass exports to layout component #378

@mxstbr

Description

@mxstbr

It would be neat if MDX automatically passed all named exports to the default exported layout component. For example, right now I have to do the following:

import BlogPost from '../../components/BlogPost';

export const meta = {
  published: true,
  title: 'Tech Choices I Regret at Spectrum',
  // ...more meta data...
}

export default ({ children }) => <BlogPost meta={meta}>{children}</BlogPost>

It would be neat if I could do this instead and BlogPost would get meta passed as a prop automatically (on top of children of course):

import BlogPost from '../../components/BlogPost';

export const meta = {
  published: true,
  title: 'Tech Choices I Regret at Spectrum',
  // ...more meta data...
}

export default BlogPost;

That way, my BlogPost could have a getInitialProps method to fetch data with Next.js. Right now, I have to asynchronously fetch data in the componentDidMount lifecycle, which is not the best user experience.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions