React Component not rendering source content when is part of another component and warning

谁说胖子不能爱 提交于 2020-03-25 13:52:13

问题


I am using MDX to display a component and its contents. I was able to get help from a SO member to get things moving along, however when using MDX + Gatsby components are not rendering as expected. Here you can see a minimal project working:

https://codesandbox.io/s/gatsby-starter-mdx-basic-21mif

<ShowHtml>
  <Test />
</ShowHtml>

using gatsby-browser.js we are able to provide the components through MDXProvider

import React from "react";
import { MDXProvider } from "@mdx-js/react";
import ShowHtml from "./src/components/ShowHtml/ShowHtml";
import Test from "./src/components/Test/Test";

const components = {
  ShowHtml,
  Test
};

export const wrapRootElement = ({ element }) => {
  return <MDXProvider components={components}>{element}</MDXProvider>;
};

Another thing to note is that a warning is displayed mentioning that the components are not being imported, and that is only for those that are being used as children:

Component Test was not imported, exported, or provided by MDXProvider as global scope 

来源:https://stackoverflow.com/questions/60309226/react-component-not-rendering-source-content-when-is-part-of-another-component-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!