diff --git a/packages/mdx/mdx-hast-to-jsx.js b/packages/mdx/mdx-hast-to-jsx.js index bdde40a89..db1e7fb22 100644 --- a/packages/mdx/mdx-hast-to-jsx.js +++ b/packages/mdx/mdx-hast-to-jsx.js @@ -108,7 +108,7 @@ function toJSX(node, parentNode = {}, options = {}) { this.layout = ${layout || 'null'} } render() { - const { components = {}, ...props } = this.props + const { components, ...props } = this.props return { ) const element = fn(React, ...Object.values(scope)) + const components = { + h1: ({children}) => + React.createElement('h1', {style: {color: 'tomato'}}, children) + } + + const elementWithProvider = React.createElement( + MDXProvider, + {components}, + element + ) - return renderToStaticMarkup(element) + return renderToStaticMarkup(elementWithProvider) } it('Should output parseable JSX', async () => { @@ -59,7 +69,7 @@ it('Should output parseable JSX', async () => { it('Should be able to render JSX with React', async () => { const result = await renderWithReact('# Hello, world!') - expect(result).toContain('

Hello, world!

') + expect(result).toContain('

Hello, world!

') }) it('Should output parseable JSX when using < or >', async () => { @@ -88,7 +98,7 @@ it('Should match sample blog post snapshot', async () => { this.layout = null; } render() { - const { components = {}, ...props } = this.props; + const { components, ...props } = this.props; return (