Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ function toJSX(node, parentNode = {}, options = {}) {
} class MDXContent extends React.Component {
constructor(props) {
super(props)
this.layout = ${layout}
this.layout = ${layout || 'null'}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could also remove the entire constructor instead if layout isn't defined.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is semantically cleaner than omitting the constructor entirely, because it's communicating that there is no user layout. null is semantically different than undefined.

}
render() {
const { components = {} } = this.props
const { components = {}, ...props } = this.props
Copy link
Member

@ChristopherBiscardi ChristopherBiscardi Nov 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't this need an equivalent change in the runtime to pass the props into createElement?

Previously, the runtime was just using the scoped names when passed in to defined the components and props variables. If we're standardizing the class to be this.props access always, then we need to pass everything into createElement in the runtime like

createElement(MDXContent, {components, ...props})


return <MDXTag
name="wrapper"
Expand Down
4 changes: 2 additions & 2 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ it('Should match sample blog post snapshot', async () => {
"export default class MDXContent extends React.Component {
constructor(props) {
super(props);
this.layout = undefined;
this.layout = null;
}
render() {
const { components = {} } = this.props;
const { components = {}, ...props } = this.props;

return (
<MDXTag name=\\"wrapper\\" components={components}>
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export default ({
...keys,
`${code}

return React.createElement(MDXContent, { components });`
return React.createElement(MDXContent, { components, ...props });`
)

return fn({}, React, ...values)
Expand Down