question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`MDXCreateElement` not using the `components` mapping prop in v1.4.5

See original GitHub issue

Subject of the issue

MDXCreateElement not using the components mapping prop

When trying to use component mapping following the mdxjs instructions from here, the mapped components’ styles don’t get rendered.

Your environment

  • OS: MacOS 10.13.5
  • Packages:
    • @mdx-js/loader”: “1.4.5”,
    • @next/mdx”: “9.0.5”,
    • “next”: “latest”,
    • “react”: “^16.7.0”,
    • “react-dom”: “^16.7.0”
  • Env:
    • node v12.10.0
    • npm v6.10.3
    • Chrome 76

Steps to reproduce

Repro: https://codesandbox.io/s/nextjs-mdx-js-tnifm

This repro is a fresh install of Next.js with only mdx-js support added.

// source: pages/index.js
import Content from "../content/hello.mdx";

const MyH1 = props => <h1 style={{ color: "tomato" }} {...props} />;
const components = {
  h1: MyH1
};

export default () => <Content components={components} />;

Expected behaviour

The h1 header should have a tomato color.

Actual behaviour

The h1 header renders black.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ghostcommented, Dec 3, 2019

Actually, it doesn’t make sense to pass components on the Markdown component. Instead we have to wrap it with the MDXProvider on which we pass components.

This is the good way to do it :

import React from 'react'
import { MDXProvider } from '@mdx-js/react'

import Content from "../content/hello.mdx"

const components = {
  h1:  props => <h1 style={{ color: "tomato" }} {...props} />
}

export default () => (
  <MDXProvider components={components}>
    <Content />
  </MDXProvider>
)
0reactions
wooormcommented, Oct 20, 2021

Finally fixed btw! Please try out the RC for MDX 2: https://v2.mdxjs.com

Read more comments on GitHub >

github_iconTop Results From Across the Web

MDXCreateElement not using the components mapping prop
MDXCreateElement ` not using the `components` mapping prop in v1.4.5.
Read more >
Controls - Storybook - JS.ORG
Storybook Controls gives you a graphical UI to interact with a component's arguments dynamically without needing to code. It creates an addon panel...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found